Created
April 9, 2021 08:32
-
-
Save paulmwatson/b76f7171e05b891f5ea1b48e7c5b3fd1 to your computer and use it in GitHub Desktop.
Python assignment expressions (if/conditional assignments)
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
d = {'a': True, 'b': False} | |
# Without assignment expressions | |
if d['a']: | |
a = d['a'] | |
print(a) | |
# => True | |
if d['b']: | |
b = d['b'] | |
print(b) | |
# => | |
# Using assignment expressions | |
if a := d['a']: | |
print(a) | |
# => True | |
if b := d['b']: | |
print(b) | |
# => |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment