def main():
print("hello")
main()
1 + 1
1 - 2
2 * 3
3 / 2
7 % 3
3 // 2
2 ** 3
# <
# >
# <=
# >=
# ==
# !=숫자
정수
int
bool
실수
float
시퀀스
불변
가변
list
tuple
str
bytes
집합
매핑
dict
set
name = input("이름을 입력하세요: ")
print("hello,", name)
print("hello, " + name)
print("hello, %s" % name)name = input("이름을 입력하세요: ")
print("hello,", name)
print("hello, " + name)
print("hello, %s" % name)print("hello, {}".format(name))
# 3.6 버전부터 사용 가능
print(f"hello, {name}")if True and False:
pass
elif False or False:
pass
elif not None:
pass
else:
passwhile True:
passfor i in range(10):
print(i)while (true) {
// ...
}
for (;;) {
// ...
}p
y
t
h
o
nvalue = "python"
for c in range(len(value)):
print(c)for c in "python":
print(c)# str
string = "python"
# list
rainbow = ["빨강", "주황", "노랑", "초록", "파랑", "남", "보라"]
# tuple
color = (255, 255, 0)# str
string = "python"
# list
rainbow = ["빨강", "주황", "노랑", "초록",
"파랑", "남", "보라"]
# tuple
color = (255, 255, 0)# str
string = "python"
string[2:]
# list
rainbow = ["빨강", "주황", "노랑", "초록",
"파랑", "남", "보라"]
rainbow[:4]
# tuple
color = (255, 255, 0)
color[::2]"hello, world"[::-1]x = 1
y = 2
z = x, yx = 1
y = 2, 3
z = x, yx = 1
y = 2
z = x, y
a, b = zx, y = y, x| 입력 | 출력 |
|---|---|
| [[1], [2]] | [1,1] |
| [[1, 2], [3, 4], [5]] | [2,2,1] |
[x for x in range(1, 21) if not x & 1]sum(range(1, 101))numbers = [1, 1, 2, 3, 5, 8, 8]numbers = [1, 1, 2, 3, 5, 8, 8]
print(set(numbers))sizes = [..., "S", ..., "M", ..., "L"]
sizes = {90: "S", 95: "M", 100: "L"}# person_a
"학생", "공대", "합리", "창의", "비판"
# person_b
"학생", "공대", "열정", "호기심", "변화"
def add(x, y):
return x + y
add(1, 2)
def add(x, y):
x.append(y)
numbers = []
print(numbers)
# Output: []
add(numbers, 1)
print(numbers)
# Output: ?
class Snake:
passclass Snake:
pass
snake = Snake()
print(snake)
class Snake:
def __init__(self):
self.length = 1class Snake:
def __init__(self):
self.length = 1
snake = Snake()
print(snake.length)
class Snake:
def __init__(self, length):
self.length = length
snake = Snake(2)
print(snake.length)
class Snake:
def __init__(self, length):
self.length = length
snake = Snake(2)
print(snake.length)class Snake:
def __init__(self, length):
self.length = length
def change_length(self, length):
self.length = length
snake = Snake(2)
print(snake.length)
snake.change_length(snake.length + 1)
print(snake.length)# 3.7
from dataclasses import dataclass
@dataclass
class Snake:
length: int
def change_length(self, length):
self.length = length
def add(x):
return x ** 2
x = map(add, range(10))
print(list(x))
def add(x):
return x ** 2
x = map(add, range(10))
print(next(x))
for i in range(100000000000):
print(i)