6 ms·
Yes, but why? Actually, it's No, because python culture aims to use one way to do thing, the least surprising one. In this case it's: def f(x=None): if x is
by iki23 14y ago
Yes, but why? Actually, it's No, because python culture aims to use one way to do thing, the least surprising one. In this case it's:
def f(x=None): if x is None: x = []
- SoftwareMaven 14y agoBecause that "if" is a statement whereas the ternary expression is, well, an expression. There are places expressions can be used that statements can't (eg lambdas) and that x or [] won't work (eg when x is False). That said, people still seem to favor your form as the more Pythonic way. Personally, I think that's just because the ternary expression is relatively new.