Created at : 2024-12-25 15:29
Auther: Soo.Y
๐๋ฉ๋ชจ
์ฐ์ฐ๊ณผ ๋ณ์
print("์๋
") # ๋ฌธ์ ์ถ๋ ฅ
1 + 3 # ์ฐ์ฐ
ํจ์
def get_cost(num_coins: int, values: int) -> int:
cost = num_coins * values
print(f"{cost}์
๋๋ค.")
return cost
# ์ ์ธํ ํจ์ ์ฌ์ฉํ๊ธฐ
get_cost(3, 100)
Data Types
์ ์ํ
x = 10
print(x) # 10
print(type(x)) # <class 'int'>
์ค์ํ
y = 12.46789378972
print(y) # 12.46789378972
print(type(y)) # <class 'float'>
Booleans
z_one = True
print(z_one) # True
print(type(z_one)) # <class 'bool'>
z_two = False
print(z_two) # False
print(type(z_tow)) # <class 'bool'>
z_three = (1 < 2)
print(z_three) # True
print(type(z_three)) # <class 'bool'>
z_four = (5 < 3)
print(z_four) # False
print(type(z_four)) # <class 'bool'>
z_five = not z_four
print(z_five) # True
print(type(z_five)) # <class 'bool'>
๋ฌธ์์ด
word = "์๋
"
print(word) # ์๋
print(type(word)) # <class 'str'>
my_number = "1.2345"
print(my_number) # "1.2345"
print(type(my_number)) # <class 'str'>
float_my_number = float(my_number)
print(float_my_number) # 1.2345
print(type(float_my_number)) # <class 'float'>
new_string = "์" + "๋
"
print(new_string) # ์๋
print(type(new_string))
there_sting = "์๋
" * 3
print(there_sting) # ์๋
์๋
์๋
print(type(there_sting))
print(False + False) # 0
print(True + False) # 1
print(False + True) # 1
print(True + True) # 2
print(False + True + True + True) # 3
์กฐ๊ฑด๋ฌธ
Symbol | ์๋ฏธ |
---|---|
== | ๊ฐ๋ค |
!= | ๊ฐ์ง ์๋ค. |
< | ์๋ค |
โ | ์๊ฑฐ๋ ๊ฐ๋ค. |
> | ํฌ๋ค |
>= | ํฌ๊ฑฐ๋ ๊ฐ๋ค. |
if ์กฐ๊ฑด:
์คํํ ์ฝ๋
x = 10
if x > 5:
print("x๋ 5๋ณด๋ค ํฝ๋๋ค.")
# if-else ๋ฌธ
x = 3
if x > 5:
print("x๋ 5๋ณด๋ค ํฝ๋๋ค.")
else:
print("x๋ 5๋ณด๋ค ํฌ์ง ์์ต๋๋ค.")
# if-elif-else๋ฌธ
x = 7
if x > 10:
print("x๋ 10๋ณด๋ค ํฝ๋๋ค.")
elif x > 5:
print("x๋ 5๋ณด๋ค ํฌ์ง๋ง 10๋ณด๋ค ์๊ฑฐ๋ ๊ฐ์ต๋๋ค.")
else:
print("x๋ 5๋ณด๋ค ์๊ฑฐ๋ ๊ฐ์ต๋๋ค.")
๋ฆฌ์คํธ(List)
# ๋ฆฌ์คํธ ๋ง๋ค๊ธฐ
fruits = ["์ฌ๊ณผ", "๋ฐ๋๋", "์ฒด๋ฆฌ"]
print(fruits) # ["์ฌ๊ณผ", "๋ฐ๋๋", "์ฒด๋ฆฌ"]
# ๋ฆฌ์คํธ ๊ธธ์ด
print(len(fruits)) # 3
# ๋ฆฌ์คํธ ์์ ์ ๊ทผ
print(fruits[0]) # "์ฌ๊ณผ"
print(fruits[-1]) # "์ฒด๋ฆฌ" (๋ง์ง๋ง ์์)
# ๋ฆฌ์คํธ ์์ ๋ณ๊ฒฝ
fruits[1] = "๊ทค"
print(fruits) # ["์ฌ๊ณผ", "๊ทค", "์ฒด๋ฆฌ"]
# ๋ฆฌ์คํธ ์์ ์ ๊ฑฐ
fruits.remove("์ฒด๋ฆฌ")
print(fruits) # ["์ฌ๊ณผ", "๋ฐ๋๋"]
# ๋ฆฌ์คํธ ์์ ์ถ๊ฐ
fruits.append("์ฒด๋ฆฌ")
print(fruits) # ["์ฌ๊ณผ", "๊ทค", "์ฒด๋ฆฌ"]
# ๋ฆฌ์คํธ ์ ๋ ฌํ๊ธฐ
numbers = [3, 1, 4, 7, 2]
number.sort()
print(number) # [1, 2, 3, 4, 7]