1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# 반복문
hit = 0
while hit < 10:
print("hit")
hit += 1
for num in [1, 2, 3, 4, 5]:
print(num)
if num > 3:
break
for num in range(10, 15): # [10, 15)
print(num)
numlist = [1, 2, 3, 4, 5]
list1 = [x for x in numlist]
print(list1) # [1, 2, 3, 4, 5]
list2 = [x for x in numlist if x%2 == 0]
print(list2) # [2, 4]
list3 = [x*y for x in range(2, 3) for y in range(1, 10)]
print(list3) # [2, 4, 6, 8, 10, 12, 14, 16, 18]
# 조건문
price = 1000
if price > 800:
print("800 초과")
elif price > 500:
print("500 초과")
else:
print("500 미만")
name = "주니"
age = 10
if name == "주니" and age == 10: # and, or, not
print(name, age)
list = [1, 2, 3]
if 1 in list:
print(True)
if 4 not in list:
print(True)
# 조건 연산자
score = 90
result = (10 if score>80 else 20)
print(result) # 10
|
cs |
반응형
'프로그래밍 언어 > Python' 카테고리의 다른 글
(Python) 클래스, 상속 (0) | 2021.11.24 |
---|---|
(Python) 함수 (0) | 2021.10.19 |
(Python) 문자열 (0) | 2021.10.19 |
(Python) 튜플, 딕셔너리, 집합(set) (0) | 2021.10.18 |
(Python) 리스트(List) (0) | 2021.10.18 |