생활코딩

Coding Everybody

코스 전체목록

닫기

반복문

수업소개

조건을 만족하는 동안 동일한 작업을 반복적으로 실행하도록 하는 반복문을 알려주는 수업입니다. 

 

 

강의

유튜브에서 수업보기

 

 

 

소스코드

5_1_for_basic.py

names = ['egoing', 'basta', 'blackdew', 'leezche']
for name in names:
    print('Hello, '+name+' . Bye, '+name+'.')

 

 

 

강의

유튜브에서 수업보기

 

 

 

소스코드

5_2_for_multi_demensional.py 

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)

 

 

 

강의

유튜브에서 수업보기

 

 

 

소스코드

5_3_for_dictionary.py

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('-----------------')

 

댓글

댓글 본문
  1. 새로운도전
    23.12.13
  2. 코딩두
    23.07.30
  3. 오늘의케빈
    20230317
  4. 개굴이
    230104
  5. 데이비드15
    220823
  6. 임앤강
    2022-06-18
  7. negoist
    220413
  8. 로디아빠
    2022.03.18 완료요
  9. sdfddf
    https://realbylongines.tistory.com......755

    파이썬 반복문 정리
  10. yeop6134
    5_1_for_basic.py 소스코드에서
    마지막줄 print('Hello, '+name+' . Bye, '+name+'.') 에
    +는 어떤 역할을 하는건가요?
  11. pmxsg
    2022.02.08
  12. gaheebella
    2022.01.21 완료
  13. Birok
    2022. 01. 13 완료01
  14. 낀찐
    2022. 01. 06 완료
  15. 나무빠따
    수강완료했습니다. 감사합니다.
  16. 솔나무
    - for value in list
    - 리스트: A, B, C = [a, b, c]
    - for key in dictionary

    for key와 for list의 활용

    순서를 활용할때 list
    순서보단 이름을 줄때 dictionary
  17. labis98
    20210828 good!!!
  18. 이마누
    완료
graphittie 자세히 보기