본문 바로가기
Python

[Python] string, dictionary, tuple을 for in 반복문과 같이 사용해보기

by 코딩하는 붕어 2021. 11. 20.
반응형

🍙 String

>>> for i in 'abcde':
...     print(i)
...     
a
b
c
d
e



🍙 dictionary

>>> dict = {1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e'}

>>> for i in dict:
...     print('num: {}, string: {}'.format(i, dict[i]))
...     
num: 1, string: a
num: 2, string: b
num: 3, string: c
num: 4, string: d
num: 5, string: e



🍙 tuple

>>> tuple = (1, 2, 3, 4, 5)

>>> for i in tuple:
...     print(i)
...     
1
2
3
4
5
반응형

'Python' 카테고리의 다른 글

[Python] 자료형  (0) 2021.11.20
[Python] for과 while문의 차이  (0) 2021.11.20
[Python] List 자료형의 메소드  (0) 2021.11.20
[Python] 객체, 가변객체, 불변객체  (0) 2021.11.20
[Python] 클래스나 변수 등을 포함한 모듈  (0) 2021.04.12

댓글