Y
Hacker News
new
|
ask
|
show
|
jobs
by
nighthawk454
1057 days ago
I think it's even more safe/preferable to use non-mutable `None`s as a default and do:
``` def myfunc(x=None): x = x if x is not None else [] ... ```
1 comments
memco
1057 days ago
In some cases you can also do:
x = x or []
Your method is best when you might get falsy values but if that’s not an issue the `or` method is handy.
link
aunderscored
1056 days ago
I tend to dislike this method as it's unclear what or returns unless you already know that or behaves this way. x if x is not None else default is cleaner in my opinion
link