4 ms·
I think the Python ternary is best read as "DEFAULT_VALUE if COMMON_CASE else FALLBACK", and is best used in situations where this is what is meant semantically
by rcthompson 5y ago
I think the Python ternary is best read as "DEFAULT_VALUE if COMMON_CASE else FALLBACK", and is best used in situations where this is what is meant semantically. If you're dealing with two equally plausible code paths, the standard if/else branching structure makes that more clear.
- albrewer 5y agoThis is how I use it. If I want an empty list as a default argument for some function, I do something like this: def foo(things: Optional[List[str]] = None) -> None: thing_list = things if things else [] ...