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]

๐Ÿ“œ์ถœ์ฒ˜(์ฐธ๊ณ  ๋ฌธํ—Œ)


๐Ÿ”—์—ฐ๊ฒฐ ๋ฌธ์„œ