Created
October 23, 2015 15:05
-
-
Save datamafia/9b321656dc86d4cf2460 to your computer and use it in GitHub Desktop.
Use of "or" in conjunction with update for setting variables
This file contains hidden or 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
d = dict() | |
d['a'] = 1 | |
d.update( | |
{ | |
'a': 2 | |
} | |
) | |
print d | |
f = None | |
d.update( | |
{ | |
'a': f or 3 | |
} | |
) | |
print d | |
f = 5 | |
d.update( | |
{ | |
'a': f or 4 | |
} | |
) | |
print d | |
# {'a': 2} | |
# {'a': 3} | |
# {'a': 5} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment