반응형
리스트와 정수의 곱셈
문제 코드:
numbers = [1, 2, 3]
result = numbers * numbers
오류 메시지:
TypeError: can't multiply sequence by non-int of type 'list'
해결 방법: 리스트를 정수와 곱해서 반복하거나, 두 리스트를 병합하려면 + 연산자를 사용해야 합니다.
# 리스트를 정수와 곱해서 반복
result = numbers * 3
# 두 리스트를 병합
result = numbers + numbers
#python #error #debug #typeerror
반응형
'파이썬 > 에러 디버깅' 카테고리의 다른 글
IndexError (0) | 2024.08.18 |
---|---|
TypeError: 'int' object is not callable (0) | 2024.08.17 |
TypeError: can only concatenate str (not "int") to str (0) | 2024.08.17 |
NameError: name 'greet' is not defined (0) | 2024.08.10 |
NameError: name 'nam' is not defined (0) | 2024.08.10 |