Skip to content

Instantly share code, notes, and snippets.

@datamafia
Created October 23, 2015 15:05
Show Gist options
  • Save datamafia/9b321656dc86d4cf2460 to your computer and use it in GitHub Desktop.
Save datamafia/9b321656dc86d4cf2460 to your computer and use it in GitHub Desktop.
Use of "or" in conjunction with update for setting variables
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