python_integer_boolean_정수의_불리언

nowhere·2022년 1월 19일
0
  • 파이썬에서는 크게 쓸 일이 없지만, 문득, 파이썬에서의 정수들의 참/거짓에 대한 판별이 궁금해졌다.
  • 언어마다 다른 특징을 가지고 있다는 점에서 알아둘 필요는 있겠다.
if len(''):
    print('0 is treated as True')
else:
    print('0 is treated as False') # executed
    
if -1:
    print('-1 is treated as True') # executed
else:
    print('-1 is treated as False')
    
if 1:
    print('of course, True') # executed
else:
    print('what?')

print(bool(0)) # False
print(bool(-1)) # True
print(bool(1)) # True
profile
수익성은 없으니 뭐라도 적어보는 벨로그

0개의 댓글