조건을 만족하는 동안 작업을 반복적으로 수행하는 반복문이다.
직접 실행시켜본 결과이다.
names = ['egoing', 'basta', 'blackdew', 'leezche']
for name in names:
print('Hello, '+name+' . Bye, '+name+'.')
Hello, egoing . Bye, egoing.
Hello, basta . Bye, basta.
Hello, blackdew . Bye, blackdew.
Hello, leezche . Bye, leezche.
persons = [
['egoing', 'Seoul', 'Web'],
['basta', 'Seoul', 'IOT'],
['blackdew', 'Tongyeong', 'ML'],
]
print(persons[0][0])
for person in persons:
print(person[0]+','+person[1]+','+person[2])
person = ['egoing', 'Seoul', 'Web']
name = person[0]
address = person[1]
interest = person[2]
print(name, address, interest)
name, address, interest = ['egoing', 'Seoul', 'Web']
print(name, address, interest)
for name, address, interest in persons:
print(name+','+address+','+interest)
egoing
egoing,Seoul,Web
basta,Seoul,IOT
blackdew,Tongyeong,ML
egoing Seoul Web
person = {'name':'egoing', 'address':'Seoul', 'interest':'Web'}
print(person['name'])
for key in person:
print(key, person[key])
persons = [
{'name':'egoing', 'address':'Seoul', 'interest':'Web'},
{'name':'basta', 'address':'Seoul', 'interest':'IOT'},
{'name':'blackdew', 'address':'Tongyeong', 'interest':'ML'}
]
print('==== persons ====')
for person in persons:
for key in person:
print(key, ':', person[key])
print('-----------------')
egoing
name egoing
adress Seoul
interest Web
==== persons ====
name : egoing
adress : Seoul
interest : Web
-----------------
name : basta
adress : Seoul
interest : IOT
-----------------
name : blackdew
adress : Tongyeong
interest : ML
-----------------
list 는 대괄호로 묶음
사전형 dictionary type 연관배열 해쉬는 { } 중괄호를 통해서
'Python_기초 (Python)' 카테고리의 다른 글
[파이썬_제어문] 조건문 (Conditional Statement) (1) | 2022.09.02 |
---|---|
[파이썬_제어문] 비교 연산자 (Comparison Operator) (1) | 2022.09.01 |
[파이썬_제어문] Boolean (1) | 2022.09.01 |
[파이썬] PyPi (0) | 2022.09.01 |
[파이썬] 디버깅 (debugging) (0) | 2022.09.01 |
댓글