Created
April 1, 2022 15:56
-
-
Save pmbrull/3f144b4fdc39f006b5f46f69a3647e1a to your computer and use it in GitHub Desktop.
Python truth 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
help(int) | |
[...] | |
| __bool__(self, /) | |
| self != 0 | |
[...] | |
help(str) | |
[...] | |
| __len__(self, /) | |
| Return len(self). | |
[...] | |
""" | |
# Let's apply the __bool__ logic for `int` | |
bool(10) # True | |
bool(0) # False | |
# Now, check the __len__ and boolean cast for `str` | |
len("hello") # 5 | |
bool("hello") # True | |
len("") # 0 | |
bool("") # False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment