[Python] math ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
ยท
๐Ÿ“Language/โž• Python
math ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ฌ์šฉํ•˜๊ธฐ import matha = 4b = 5c = 1.6# ์ตœ๋Œ€ ๊ณต์•ฝ์ˆ˜ ๊ตฌํ•˜๊ธฐ => 1gcd = math.gcd(a, b)# ์ตœ์†Œ ๊ณต๋ฐฐ์ˆ˜ ๊ตฌํ•˜๊ธฐ => 20(a * b) // math.gcd(a, b) # python 3.8 ๋ฒ„์ „ ์ดํ•˜math.lcm(a, b) # python 3.9 ๋ฒ„์ „ ์ด์ƒ# ์ œ๊ณฑ๊ทผ ๊ตฌํ•˜๊ธฐmath.sprt(a)# ์†Œ์ˆ˜ ์˜ฌ๋ฆผํ•ด์„œ ์ •์ˆ˜ ๊ตฌํ•˜๊ธฐ => 2math.ceil(c)# ์†Œ์ˆ˜ ๋ฒ„๋ฆผํ•ด์„œ ์ •์ˆ˜ ๊ตฌํ•˜๊ธฐ => 1math.floor(c)
[Python] ๋”•์…”๋„ˆ๋ฆฌ
ยท
๐Ÿ“Language/โž• Python
๋”•์…”๋„ˆ๋ฆฌ : ํ‚ค-๊ฐ’ ์Œ์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๋Š” ์ž๋ฃŒํ˜•dict = {key1:value1, key2: value2} person = { "name": "Alice", "age": 30, "city": "New York"}# ๊ฐ’ ์ถœ๋ ฅ => "Alice"print(person["name"])# ๊ฐ’ ๋ณ€๊ฒฝperson["age"] = 25# ๊ฐ’ ์ถ”๊ฐ€person["email"] = "alice@gmail.com"# ๊ฐ’ ์‚ญ์ œdel person["email"]# key ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธif "name" in person: print("์กด์žฌํ•จ") ๋ฉ”์„œ๋“œperson = { "name": "Alice", "age": 30, "city": "New York"}# key๋กœ ๊ฐ’ ์กฐํšŒ, ์กด์žฌํ•˜์ง€ ์•Š์„ ๊ฒฝ..
[Python] set
ยท
๐Ÿ“Language/โž• Python
set : ์ง‘ํ•ฉ- ์š”์†Œ๊ฐ€ ์ค‘๋ณต๋˜์ง€ ์•Š๋Š”๋‹ค. (์ค‘๋ณต ์ œ๊ฑฐ)- ์š”์†Œ์˜ ์ˆœ์„œ๋Š” ๋ณด์žฅ๋˜์ง€ ์•Š๋Š”๋‹ค. arr1 = [1,2,3]# ์ง‘ํ•ฉ์œผ๋กœ ์ƒ์„ฑ => {1,2,3}s = set(arr1)# ์š”์†Œ ์ถ”๊ฐ€ => {1,2,3,4}s.add(4)# ์š”์†Œ ์ œ๊ฑฐ => {1,2,3}s.remove(4) # ์š”์†Œ๊ฐ€ ์—†์œผ๋ฉด ์—๋Ÿฌ ๋ฐœ์ƒs.discard(4) #์š”์†Œ๊ฐ€ ์—†์–ด๋„ ์—๋Ÿฌ ๋ฐœ์ƒ X s1 = {1,2,3}s2 = {2,4,6}# ํ•ฉ์ง‘ํ•ฉ => {1,2,3,4,6}print(s1 | s2)# ๊ต์ง‘ํ•ฉ => {2}print(s1 & s2)# ์ฐจ์ง‘ํ•ฉ => {1,3}print(s1 - s2)
[Python] list
ยท
๐Ÿ“Language/โž• Python
arr1 = [1,2,5,4,3]# ๋ฐฐ์—ด์—์„œ ๊ฐ’ ๋ฝ‘๊ธฐ => 4arr1[3]arr1[-2]# ๋ฐฐ์—ด์—์„œ ๊ฐ’์˜ index ๊ตฌํ•˜๊ธฐ => 3arr1.index(4)# ๋ฐฐ์—ด ๊ธธ์ด ๊ตฌํ•˜๊ธฐ => 5len(arr1)# ๋ฐฐ์—ด ์ตœ๋Œ€๊ฐ’ ๊ตฌํ•˜๊ธฐ => 5max(arr1)# ๋ฐฐ์—ด ํ•ฉ๊ณ„ ๊ตฌํ•˜๊ธฐ => 15sum(arr1)# ๋ฌธ์ž์—ด๋กœ ์ถœ๋ ฅ => '12543'''.join(arr1)  ๋ณ€๊ฒฝarr1 = [1,2,3]# ๊ฐ’ ์ถ”๊ฐ€ => [1,2,3,4]arr1.append(4)# ํŠน์ • ์ธ๋ฑ์Šค์— ๊ฐ’ ์ถ”๊ฐ€ => [1,4,2,3]arr1.insert(4, 1)# ํŠน์ • ๊ฐ’ ์‚ญ์ œ => [1,2]arr1.remove(3)  ์ •๋ ฌarr1 = [1,2,5,4,3]# ๋ฐฐ์—ด ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ => [1,2,3,4,5]arr1.sort()# ๋ฐฐ์—ด ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ =>..
[Python] ์ •์ˆ˜
ยท
๐Ÿ“Language/โž• Python
num1 = 5num2 = 8# ์ •์ˆ˜๋ฅผ ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜ => '5'str(num1)# 0 ๋ถ€ํ„ฐ ์ฃผ์–ด์ง„ ์ˆซ์ž๊นŒ์ง€ ์ˆซ์ž ์ƒ์„ฑ => range(0, 5)range(5)# list๋กœ ๋‚˜์—ด => [0, 1, 2, 3, 4]list(range(5))# ๊ฐ€์žฅ ํฐ ์ˆ˜ ์ฐพ๊ธฐ => 8max(num1, num2)# ๋‚˜๋ˆ„๊ธฐ(๋ชซ์„ ์ •์ˆ˜๋งŒ ๋‚จ๊ธฐ๊ธฐ) => 28//3# ์ œ๊ณฑ ๊ตฌํ•˜๊ธฐ => 273**3# ์ œ๊ณฑ๊ทผ ๊ตฌํ•˜๊ธฐ => 39**0.5  ํƒ€์ž… ๋ณ€ํ™˜num1 = 123# ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜ => '123'str(num1)# ๋ฐฐ์—ด๋กœ ๋ณ€ํ™˜1 => [1,2,3][int(i) for i in str(num1)]
[Python] ๋ฌธ์ž์—ด
ยท
๐Ÿ“Language/โž• Python
inputstr1 = input() ๋ฌธ์ž์—ด๋ณ€ํ˜•str1 = 'Hello'str2 = ' Python'# ํ•ฉ์น˜๊ธฐ => 'Hello Python'str1 + str2# ๊ธธ์ด ๊ตฌํ•˜๊ธฐ => 5len(str1)# ์•ž๋’ค ๊ณต๋ฐฑ ์ œ๊ฑฐํ•˜๊ธฐ => 'Python'str2.strip()# ๋Œ€๋ฌธ์ž๋กœ ๋ณ€ํ™˜ => 'HELLO'st1.upper()# ์†Œ๋ฌธ์ž๋กœ ๋ณ€ํ™˜ => 'hello'str1.lower()# ๋Œ€์†Œ๋ฌธ์ž ์„œ๋กœ ๋Œ€์น˜ ๋ณ€ํ™˜ => 'hELLO'strq.swapcase()  ํƒ€์ž… ๋ณ€ํ™˜str1 = 'Hello Python'str2 = '100'arr = ['Hello', 'Python']# ์ •์ˆ˜๋กœ ๋ณ€ํ™˜ํ•˜๊ธฐ => 100int(str2)# list๋กœ ๋ณ€ํ™˜ํ•˜๊ธฐ (๊ณต๋ฐฑ๊ธฐ์ค€) => ['Hello', 'Python']str1.split(' '..
[Python] ๋ณ€์ˆ˜/ ๋ณ€์ˆ˜ ํƒ€์ž…
ยท
๐Ÿ“Language/โž• Python
๋ณ€์ˆ˜ ์„ ์–ธ hello = "๋ณ€์ˆ˜ ์‚ฌ์šฉํ•˜์—ฌ ๊ธด๋ฌธ์žฅ ์ถœ๋ ฅํ•˜๊ธฐ" print(hello) ๋ณ€์ˆ˜ ํƒ€์ž… #type(๋ณ€์ˆ˜๋ช…) -๋ณ€์ˆ˜์˜ํ˜•ํƒœ ํ™•์ธํ•˜๊ธฐ num1 = 100 print(type(num1)) #int num2 = "100" print(type(num2)) #str num3 = 0.1 print(type(num3)) #float word = True print(type(word)) #bool plus1 = num1+20 print(plus1) plus2 = num2+"20" print(plus2)
[Python] ์ถœ๋ ฅ / ์ฃผ์„
ยท
๐Ÿ“Language/โž• Python
์ถœ๋ ฅ print("Hello World") - print ํ•จ์ˆ˜๋Š” ์†Œ๋ฌธ์ž๋กœ ์“ฐ๊ธฐ - ' (์ž‘์€๋”ฐ์˜ดํ‘œ)๋‚˜ " (ํฐ๋”ฐ์˜ดํ‘œ) ๋‘˜๋‹ค ์‚ฌ์šฉ๊ฐ€๋Šฅ - pr + Tab + ( = ์ž๋™์ž…๋ ฅ ์‰˜์ฐฝ์—์„œ ์‹คํ–‰ ์—๋””ํ„ฐ์ฐฝ์—์„œ ์‹คํ–‰ - ์ฝ”๋“œ์ž…๋ ฅ -> ์ €์žฅ(Ctrl+S) -> ์‹คํ–‰(F5) #๋ฌธ์ž๋ฅผ ์ถœ๋ ฅํ• ๋•Œ๋Š” ์ž‘์€๋”ฐ์˜ดํ‘œ๋‚˜ ํฐ๋”ฐ์˜ดํ‘œ ์ž…๋ ฅ print("Hello Python") #์ˆซ์ž๋ฅผ ์ถœ๋ ฅํ• ๋•Œ๋Š” ์ž…๋ ฅX print(10) #์ˆซ์ž์— ์ž‘์€๋”ฐ์˜ดํ‘œ๋‚˜ ํฐ๋”ฐ์˜ดํ‘œ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ˆซ์ž๊ฐ€ ์•„๋‹Œ ๋ฌธ์ž๋กœ ์ธ์‹ print('10') print(10+10) print('10+10') ์ฃผ์„ - ํ•œ์ค„ ์ฃผ์„ : # - ์—ฌ๋Ÿฌ์ค„ ์ฃผ์„ : ''' ''' or """ """ print('Hello Python') #print('Hello Hello') print('ํ•œ์ค„ ์ฃผ์„')..
[Python] Window - ์„ค์น˜ / ํ™˜๊ฒฝ์„ค์ • / ๊ตฌ์„ฑ
ยท
๐Ÿ“Language/โž• Python
2๊ฐ€์ง€์ค‘์—์„œ ํ•˜๋‚˜ ์„ ํƒํ•ด์„œ ๋‹ค์šด - PyCharm (์ถ”์ฒœ) - IDLE PyCharm ์‚ฌ์šฉํ•˜๊ธฐ ์„ค์น˜ https://www.jetbrains.com/ko-kr/pycharm/download/#section=windows ๋‹ค์šด๋กœ๋“œ PyCharm: JetBrains๊ฐ€ ๋งŒ๋“  ์ „๋ฌธ ๊ฐœ๋ฐœ์ž์šฉ Python IDE www.jetbrains.com - Community ๋ฒ„์ „ ๋‹ค์šด๋ฐ›๊ธฐ (์ด๊ฒŒ ๋ฌด๋ฃŒ์ž„) - '์ƒˆ ํ”„๋กœ์ ํŠธ' ํด๋ฆญ > ์œ„์น˜์™€ ์ด๋ฆ„ ์ •ํ•˜๊ณ  > '์ƒ์„ฑ' ํด๋ฆญ ํ™˜๊ฒฝ์„ค์ • ๊ตฌ์„ฑ ์‰˜์ฐฝ - ํ•˜๋‹จ์˜ 'Python ์ฝ˜์†”' ํด๋ฆญ ์—๋””ํ„ฐ์ฐฝ - ์ƒ์„ฑํ•œ ํŒŒ์ผ์— ์ฝ”๋“œ์ž‘์„ฑ > ํŒŒ์ผ ์—์„œ ๋งˆ์šฐ์Šค ์˜ค๋ฅธ์ชฝ > ์‹คํ–‰ IDLE ์‚ฌ์šฉํ•˜๊ธฐ ์„ค์น˜ https://www.python.org/ Welcome to Python.org The official ..