Search

for

[- Disclaimer -] 아래 내용은 정보보안 공부 목적으로 작성된 것이나, 이를 토대로 허가되지 않은 대상에 실습을 진행할 경우 해킹 시도로 간주하여 법적 처벌을 받을 수 있음을 알려 드립니다.
for문
✦ for문 범위 지정 시 시퀀스 자료형 혹은 반복 가능한 자료형이 들어가야 함
✧ Ex) 문자열, List, Tuple, 사전, range(), 그 외 반복 가능한 자료
for 변수 in 범위: 반복 Code
Plain Text
복사
✦ 자주 사용되지 않는 Coding Style
for 변수 in 범위: 반복 Code else: 실행 Code
Plain Text
복사
for문 범위 지정
✦ 문자열
str = "abcdef" for c in str: print(c)
Plain Text
복사
a b c d e f
Plain Text
복사
✦ List
list = [1, 2, 3, 4, 5] for c in list: print(c)
Plain Text
복사
1 2 3 4 5
Plain Text
복사
✦ 사전
ascii_codes = {'a':97, 'b':98, 'c':99} for c in ascii_codes: print(c)
Plain Text
복사
c a b
Plain Text
복사
✦ range()
for c in range(10): print(c)
Plain Text
복사
0 1 2 3 4 5 6 7 8 9
Plain Text
복사
✦ 자주 사용되지 않는 Coding Style
for 변수 in 범위: 반복적으로 실행할 Code else: 실행할 Code
Plain Text
복사