Better HN
top
new
best
ask
show
jobs
Log in
Sign up
Better HN
Comment
by
agumonkey
· 8y ago · 0 comments
do people use
x = x or []
or is it considered non idiomatic in python ?
Comments
[–]
tomchristie
8y ago
It’s okay-ish. You do need to be careful about what falsey values `x` might be tho, as it could introduce edge-case bugs.
Using `x = [] if x is None else x` is more precise.
[–]
Asooka
8y ago
I would really just write `if x is None: x = []`