-
[Python tutorial] 6. Data type - Boolean코딩/Python 2022. 12. 21. 17:12728x90
Booleans
print(10 > 9) # True print(10 == 9) # False print(10 < 9) # False
a = 200 b = 33 if b > a: # False print("b is greater than a") else: print("b is not greater than a") # b is not greater than a
Evaluate Values and Variables: bool()
- 어떤 값을 가지고 있으면 True
- 문자열이 비었다면 False
- 0이 아닌 숫자는 True
- 비어있지 않은 list, tuple, set, dict는 True
True
print(bool("Hello")) # True print(bool(15)) # True a = "" print(bool(a)) # False bool("abc") bool(123) bool(["apple", "cherry", "banana"])
False
bool(False) bool(None) bool(0) bool("") bool(()) bool([]) bool({})
class myclass(): def __len__(self): return 0 myobj = myclass() print(bool(myobj)) # False
Functions
def myFunction() : return True if myFunction(): print("YES!") else: print("NO!") # YES!
x = 200 print(isinstance(x, int)) # True
728x90'코딩 > Python' 카테고리의 다른 글
[Python tutorial] 8. Data type - Tuple (0) 2022.12.21 [Python tutorial] 7. Data type - List (0) 2022.12.21 [Python tutorial] 5. Data type - Strings (1) 2022.12.21 [Python tutorial] 4. Data type - Numbers (0) 2022.12.21 [Python tutorial] 3. Data types (0) 2022.12.21