728x90
반응형
오류 문구
C:/Users/MINJI/42seoul/algorithm/this_is_coding_test/greedy/3-4.py:5: SyntaxWarning: "is" with a literal. Did you mean "=="?
if N is 1:
C:/Users/MINJI/42seoul/algorithm/this_is_coding_test/greedy/3-4.py:7: SyntaxWarning: "is" with a literal. Did you mean "=="?
if N % K is 0:
상황
if 조건문에서 N이 1일 때와 N%K가 0일 때, 원하는 동작을 하고 싶었다.
문제 코드
while 1:
if N is 1:
break
if N % K is 0:
N /= K
해결
while 1:
if N == 1:
break
if N % K == 0:
N /= K
is를 ==으로 바꿔주면 된다.
오류가 발생하는 이유는, ==은 값(데이터)을 비교하는 것이지만 is는 레퍼런스(포인터)를 비교하기 때문이다.
is 연산자는 되도록이면 None, True, False 등을 비교할 때 사용하도록 하자.
728x90
반응형
'Python' 카테고리의 다른 글
[Python 기초] 리스트 자료형 (0) | 2021.02.01 |
---|---|
[오류 해결] TypeError: unsupported operand type(s) for &: ‘str’ and ‘str’ (0) | 2021.01.28 |
파이썬 기본 문법 - 다른 언어와 헷갈리는 부분 (0) | 2021.01.24 |