๋ถ๋ฅ ์ ์ฒด๋ณด๊ธฐ
-
ํ์ด์ฌ | #9 ํํ (๋ฐ๋ณต๋ฌธ, ๋ฉ์๋)์นดํ ๊ณ ๋ฆฌ ์์ 2023. 10. 11. 01:23
ํํ ๋ค๋ฃจ๊ธฐ ํํ ์ํํ๊ธฐ( for loop ) fruits = ("apple", "banana", "cherry") for item in fruits: print(fruits) ์ธ๋ฑ์ค๋ฒํธ๋ก๋ for ๋ฐ๋ณต๋ฌธ์ ๋๋ฆด ์ ์๋ค. fruits = ("apple", "banana", "cherry") for i in range(len(fruits)): print(fruits[i]) #apple banana cherry while ๋ฐ๋ณต๋ฌธ ๋๋ฆฌ๊ธฐ fruits = ("apple", "banana", "cherry") i = 0 while i < len(fruits): print(fruits[i]) i = i + 1 #apple banana cherry ํํ๋ผ๋ฆฌ ํฉ์น๊ธฐ fruits = ("apple", "banana"..
-
ํ์ด์ฌ | #8 ํํ ๋ค๋ฃจ๊ธฐ์นดํ ๊ณ ๋ฆฌ ์์ 2023. 9. 17. 23:40
ํํ ๋ค๋ฃจ๊ธฐ ํํ ์ฝ์ด๋ค์ด๊ธฐ fruits = ("apple", "banana", "cherry") print(fruits[1]) #๋ค์์๋ถํฐ ์ฝ์ด๋ค์ด๊ธฐ print(fruits[-1]) #์ธ๋ฑ์ค ๋ฒ์๋ก ์ ๊ทผํ๊ธฐ print(fruits[1:2]) #"banana" print(fruits[:2]) #"apple", "banana" print(fruits[1:]) #"banana", "cherry" ํน์ ํ ๊ฐ ์กด์ฌ ์ฌ๋ถ ํ์ธํ๊ธฐ in์ ์ฌ์ฉํ๋ค. fruits = ("apple", "banana", "cherry") if "apple" in fruits: print("apple is in the fruits tuple") ๊ฐ ๋ณ๊ฒฝํ๊ธฐ ํํ์ ํ ๋ฒ ๋ง๋ค์ด์ง ํ์๋ ๊ฐ์ ๋ณ๊ฒฝํ ์ ์๋ค. ๋ง์ฝ ๊ฐ์ ๋ณ๊ฒฝํ๊ณ ์ถ๋ค๋ฉด..
-
ํ์ด์ฌ | #7 ํํ์นดํ ๊ณ ๋ฆฌ ์์ 2023. 9. 16. 23:14
Tuple ํํ ์ญ์ ๋ฆฌ์คํธ์ฒ๋ผ ํ๋์ ๋ณ์์ ์ฌ๋ฌ๊ฐ์ ๊ฐ์ ์ง์ด๋ฃ์ ๋ ์ฌ์ฉํ๋ค. CREATE ์๊ดํธ() ๋ฅผ ์ฌ์ฉํด์ ์์ฑํ๋ค. fruits = ("apple", "bananas", "watermelon") print(fruits) #์์ฑ์๋ก ํํ ์์ฑํ๊ธฐ => (( )) ์๊ดํธ๋ฅผ ๋๋ฒ ๊ฒน์ณ์ ์์ฑํด์ค๋ค. names = tuple(("Jane", "Berry", "Thomas")) print(names) # ํ๋์ ๊ฐ๋ง ๋ด๊ณ ์ถ์ ๋๋ ๋ฐ๋์ ๋ค์ , ๋ฅผ ๋ถ์ฌ์ฃผ์ด์ผ ํ๋ค. fruits = ("apple" , ) print(type(fruits)) # #error names = ("Berry") print(type(names)) # READ ์์๋ฅผ ๊ฐ์ง๊ณ ์์ด, index ๋ฒํธ๋ก ํธ์ถํ ์ ์๋ค. fru..
-
ํ์ด์ฌ | #6 ๋ฆฌ์คํธ์นดํ ๊ณ ๋ฆฌ ์์ 2023. 8. 31. 21:13
๋ฆฌ์คํธ ๋ฆฌ์คํธ๋ ํ๋์ ๋ณ์์ ์ฌ๋ฌ๊ฐ์ ๊ฐ์ ์ง์ด๋ฃ์ ๋ ์ฃผ๋ก ์ฌ์ฉํ๋ค. ํ์ด์ฌ์์๋ 4๊ฐ์ ๋นํธ์ธ ์ปฌ๋ ์ ๋ฐ์ดํฐ ํ์ ์ ์ ๊ณตํ๊ณ ๋ฆฌ์คํธ๋ ๊ทธ ์ค ํ๋์ด๋ค. CREAT names = ["Jane", "Berry", "Thomas"] print(names) #list ์์ฑ์๋ก ๋ฐฐ์ด์ ์์ฑํ ์๋ ์๋ค. age = list((12, 16, 28)) index ์ฒซ๋ฒ์งธ ๊ฐ์ด index 0๋ฒ์ด๋ค. names = ["Jane", "Berry", "Thomas"] print(names[0]) "Jane" print(names[2]) "Thomas" length ๋ฐฐ์ด์ ๊ธธ์ด๋ len() ํจ์๋ก ์ถ๋ ฅํ๋ค. names = ["Jane", "Berry", "Thomas"] print(len(names)) #3 emptyNa..
-
ํ์ด์ฌ | #5 ์ฐ์ฐ์์นดํ ๊ณ ๋ฆฌ ์์ 2023. 8. 18. 23:21
์ฐ์ ์ฐ์ฐ์ ์ซ์๋ผ๋ฆฌ ๋ํ๊ณ ๋นผ๊ณ ๊ณ์ฐํ ๋ ์ฌ์ฉ๋๋ ์ฐ์ฐ์๋ค. a = 10 b = 5 print(a+b) #15 print(a-b) #5 print(a*b) #50 print(a/b) #2 print(a%b) #0 ๋์ ์ฐ์ฐ์ ๊ฐ์ ๋์ ํ ๋ ์ฌ์ฉํ๋ค. # = ์ฐ์ฐ์ x = 5 # += ์ฐ์ฐ์ x += 1 # x = x + 1 # -= ์ฐ์ฐ์ x -= 1 # x = x - 1 # *= ์ฐ์ฐ์ x *= 1 # x = x * 1 ๋น๊ต ์ฐ์ฐ์ ๋ ๊ฐ์ ๋น๊ตํ ๋ ์ฌ์ฉํ๋ค. x = 10 y = 5 z = 10 print(x == y) #false print(x == z) #true print(x != y) #true print(x > y) #true print(x < z) #false print(x 5 and..
-
ํ์ด์ฌ | #4 ๋ฐ์ดํฐํ์ (Boolean)์นดํ ๊ณ ๋ฆฌ ์์ 2023. 8. 17. 23:12
๋ถ๋ฆฌ์ธ ๋ณ์ true, false ๊ฐ์ ๋ํ๋ธ๋ค. print(20 > 10) #True print(10 == 9) #False if ์กฐ๊ฑด๋ฌธ์์ ํจ๊ป ์ฌ์ฉ๋๋ค. age = 26 age2 = 16 if age > age2: print("age is older than age2") else: print("age is not older than age2") print(bool("hello")) #๋ฌธ์์ด true๊ฐ ๋ฆฌํด print(bool([1,2,3])) # true ๊ฐ ๋ฆฌํด print(bool(12)) #true ๊ฐ ๋ฆฌํด print(bool("")) #๋น๋ฌธ์์ด false ๊ฐ ๋ฆฌํด print(bool(0)) #0 false ๊ฐ ๋ฆฌํด print(bool([])) #[] flase ๊ฐ ๋ฆฌํด print(bool(No..
-
ํ์ด์ฌ | #3 ๋ฐ์ดํฐ ํ์ (๋ฌธ์์ด)์นดํ ๊ณ ๋ฆฌ ์์ 2023. 8. 11. 21:50
๋ฌธ์์ด ์์๋ฐ์ดํ๋ ํฐ๋ฐ์ดํ๋ฅผ ์ฌ์ฉํด์ ๋ฌธ์์ด์ ํํํ ์ ์๋ค. # "Hello" = 'Hello' print("Hello") print('Hello') ์ฌ๋ฌ ๋ฌธ์์ด ๊ฐ์ ๋ฃ๊ณ ์ถ์ ๋ a = """ ์ฌ๋ฌ๋ฌธ์๋ฅผ ๋ฃ์ด๋ณด์์. ์ฌ๋ฌ๋ฌธ์๋ฅผ ๋ฃ์ด๋ณด์์. ์ฌ๋ฌ๋ฌธ์๋ฅผ ๋ฃ์ด๋ณด์์. """ a = '''์ฌ๋ฌ๋ฌธ์๋ฅผ ๋ฃ์ด๋ณด์์. ์ฌ๋ฌ๋ฌธ์๋ฅผ ๋ฃ์ด๋ณด์์. ์ฌ๋ฌ๋ฌธ์๋ฅผ ๋ฃ์ด๋ณด์์. ''' index ๊ฐ์ผ๋ก ๋ฌธ์ ์ถ๋ ฅํ๊ธฐ # index ๊ฐ 1๋ฒ ๋ฌธ์ ์ถ๋ ฅํ๊ธฐ a = "Hello world" print(a[1]) ๋ฌธ์์ด ์ํํ๊ธฐ # ๋ฌธ์์ด for ๋ฌธ ๋๋ฆฌ๊ธฐ for x in "hello": print(x) ๋ฌธ์์ด ๊ธ์ ์ ์ถ๋ ฅ : len() ํจ์ ์ฌ์ฉ a = "Hello, world" print(len(a)) ๋ฌธ์์ด ์๋ฅด๊ธฐ a = ..
-
ํ์ด์ฌ | #2 ๋ฐ์ดํฐ ํ์ (int, float, complex)์นดํ ๊ณ ๋ฆฌ ์์ 2023. 8. 3. 22:04
type() : ๋ฐ์ดํฐ์ ํ์ ์ ๋ณด๋ฅผ ์๊ณ ์ถ์ ๋ ์ฌ์ฉํ๋ ํจ์ x = 16 print(type(x)) #int ํ์ด์ฌ์์๋ ๋ณ์์ ๊ฐ์ ๋ฃ์ ๋ ์๋์ผ๋ก ๋ฐ์ดํฐ ํ์ ์ด ์ง์ ๋๋ค. ๋ฌธ์์ด ํ์ : str name = "python" name = 'python' name = str("python") ์ซ์ ํ์ : int, float, complex age = 23 #int height = 160.3 #float """ complex ํ์ ์ ๋ณต์์(a+bi)๋ฅผ ํํํ๋ ํ์ ์ด๋ค. => ํ์ด์ฌ์์๋ j๋ก ํ์๋ฅผ ํํํ๋ค. complex(์ค์๋ถ, ํ์๋ถ) """ complexNumber = 1+3j complexNumber = complex(1,3) Random Number ํ์ด์ฌ์์๋ ๋๋ค์ผ๋ก ์ซ์๋ฅผ ์ถ๋ ฅํด..