Python의 불 자료형에 대해 알아봅니다.
a = True
b = False
type(a) # <class 'bool'>
type(b) # <class 'bool'>
1 == 1 # True
2 > 1 # True
2 < 1 # False
| 값 | 참거짓 |
|---|---|
| "python" | 참 |
| "" | 거직 |
| [1, 2, 3] | 참 |
| [] | 거짓 |
| (1, 2, 3) | 참 |
| () | 거짓 |
| {'a': 1} | 참 |
| {} | 거짓 |
| 1 | 참 |
| None | 거짓 |
a = [1, 2, 3, 4]
while a:
print(a.pop())
# 4
# 3
# 2
# 1
bool('python') # True
bool('') # False
bool([1, 2, 3]) # True
bool([]) # False
bool(0) # False
bool(3) # True
True and True # True
True and False # False
False and True # False
False and False # False
True or True # True
True or False # True
False or True # True
False or False # False
not True # False
not False # True
not 1 # False
not 0 # True