3 ms·
In your version, we need to check the definition of 'condition', to see whether the 'x = 5' statement has any affects on its execution. The ternary won't assign
by chriswarbo 5y ago
In your version, we need to check the definition of 'condition', to see whether the 'x = 5' statement has any affects on its execution. The ternary won't assign the variable until we know its value.
Also, your version isn't safe to use with objects (e.g. 'myObject.x = ...'), since the initial assignment could trigger arbitrary code (properties, __setattr__, etc.).
Also, your version isn't safe to use when the right-hand-side has effects, e.g.
x = fetch_config_url() if remote else read_config_file()
- version_five 5y agoCan't be used in list comprehension either