v1= 1
while v1 < 11:
print("v1 is :", v1) #v1 is : 1 ~ v1 is : 10
v1 += 1
for v2 in range(10):
print("v2 is: ", v2) # v2 is: 0 ~ v2 is: 9
for v3 in range(1, 11):
print("v3 is:", v3) # v3 is: 1 ~ v3 is: 10
sum1 = 0
cnt1 = 1
while cnt1 <= 100:
sum1 += cnt1
cnt1 += 1
print("1 ~ 100 합 : ", sum1) # 1 ~ 100 합 : 5050
print("1 ~ 100 합 : ", sum(range(1,101))) # 1 ~ 100 합 : 5050
print("1 ~ 100 짝수 합 : ", sum(range(1,101,2))) # 1 ~ 100 짝수 합 : 2500
names = ["kim", "park", "cho", "choi", "yoo"]
for i in names:
print(" You are :", i) # You are : kim ~.... You are : yoo
word ="dreams"
for j in word:
print("word : ", j) # word : d ~... word : s
my_info = {
"name" : "kim",
"age" : 24,
"city" : "seoul"
}
# 기본값은 key 호출
for key in my_info:
print("my_info : ", key) # my_info : , name my_info : age , my_info : city
#값
for key in my_info.values():
print("my_info : ", key) # my_info : kim , my_info : 24 , my_info : seoul
# 키
for key in my_info.keys():
print("my_info : ", key) # my_info : , name my_info : age , my_info : city
# 값 and 키
for k,v in my_info.items():
print("my_info : ", k,v) # my_info : name kim , my_info : age 24 , my_info : city seoul
# 대소문자 반대로 출력
name = "KeenRY"
for n in name:
if n.isupper():
print(n.lower())
else:
print(n.upper())
# k E E N r y
numbers = [14, 3, 4, 7, 10, 24, 17, 2, 33, 15, 34, 36, 38]
for num in numbers:
if num ==33:
print("found : 33!")
break
else:
print("not found : 33!")
# not found : 33!
(반복문이 정상적으로 수행 된 경우 else 블럭 수행, break 들어갔다는 것은 반복문 정상 수행된것이 아니므로 for의 else문은 실행되지 않음)
for num in numbers:
if num ==33:
print("found : 33!")
break
else:
print("not found : 33!")
else:
print("Not found 33...")
lt = ["1", 2, 5, True, 4.3, complex(4)]
for v in lt:
if type(v) is float:
continue
print("타입 :", type(v))
# 타입 : <class 'str'>
# 타입 : <class 'int'>
# 타입 : <class 'int'>
# 타입 : <class 'bool'>
# 타입 : <class 'complex'>
name = "gyomni"
print(list(reversed(name))) # ['i', 'n', 'm', 'o', 'y', 'g']
print(tuple(reversed(name))) # ('i', 'n', 'm', 'o', 'y', 'g')