[Error][Python] TypeError: 'NoneType' object is not iterable

·2023년 3월 10일
0

[Trouble Shooting]

목록 보기
1/8
post-thumbnail

에러 타입

  • TypeError: 'NoneType' object is not iterable

에러 코드


    lottos = list(random.sample(range(1, 46), 6))

    lottoList = lottos.append(bonus)


    for n in numbers:
        for lotto in lottoList: #TypeError: 'NoneType' object is not iterable

            if n == lotto:
                corrects.append(n)

에러 상황

  • lottoList에 값을 할당했지만 계속 None으로 인식되어 에러 발생

에러 원인

  • 리스트에 얕은 복사를 이용해서 값 할당

에러 해결

    #변경 전
    lottoList = lottos.append(bonus)
    
    #변경 후
    lottoList = lottos.copy()
    lottoList.append(numbers)



이거 해결하는데 1시간 넘게 걸렸다,,,심지어 저 코드는 필요없는 코드였음,, 하지만 에러 해결하는법 알았으니 좋은거지^-^
profile
개발하고싶은사람

0개의 댓글