300x250
alpha = ['a', 'b', 'c']
digit = [1, 2, 3]
alpha와 digit을 입력으로
a 1
b 2
c 3
과 같은 결과를 얻고 싶은 경우
alpha = ['a', 'b', 'c']
digit = [1, 2, 3]
for s1, s2 in alpha, digit:
print(s1, s2)
결과: ValueError: too many values to unpack (expected 2) 에러 발생
alpha와 digit의 element 개수가 3개인데 입력을 받는 s1, s2가 두 개이므로 에러 발생
alpha = ['a', 'b', 'c']
digit = [1, 2, 3]
for s1, s2, s3 in alpha, digit:
print(s1, s2, s3)
결과:
a b c
1 2 3
출력은 되지만 원하는 결과가 다름
alpha = ['a', 'b', 'c']
digit = [1, 2, 3]
for s1, s2 in zip(alpha, digit):
print(s1, s2)
결과:
a 1
b 2
c 3
zip 함수를 사용하면, alpha와 digit의 element를 하나씩 s1과 s2에 할당해서 원하는 결과와 동일한 값을 출력할 수 있음
300x250
'Python' 카테고리의 다른 글
python office automation으로 열려진 워드의 문서 민감도 레이블 설정 (set sensitivity label) (0) | 2023.05.02 |
---|---|
AttributeError: module 'win32com.gen_py.' has no attribute 'CLSIDToClassMap' (0) | 2023.05.02 |
python을 사용해서 Office에서 이미지 추출 (0) | 2023.04.06 |
python을 사용해서 오피스 문서 포맷 변환 (0) | 2023.04.06 |
ImportError: DLL load failed while importing win32api: 지정된 모듈을 찾을 수 없습니다. (0) | 2022.02.05 |