Last active
June 15, 2020 08:21
-
-
Save jahe/3ee861b74b726e79b9126441bcd398e2 to your computer and use it in GitHub Desktop.
Python Cheatsheet
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
# All values are considered "truthy" except for the following, which are "falsy": | |
None | |
False | |
0 | |
0.0 | |
0j | |
Decimal(0) | |
Fraction(0, 1) | |
[] - an empty list | |
{} - an empty dict | |
() - an empty tuple | |
'' - an empty str | |
b'' - an empty bytes | |
set() - an empty set | |
an empty range, like range(0) | |
objects for which | |
obj.__bool__() returns False | |
obj.__len__() returns 0 | |
# Pretty Print dictionary | |
import json | |
print(json.dumps({'a':2, 'b':{'x':3, 'y':{'t1': 4, 't2':5}}}, sort_keys=True, indent=4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment