Assignment with “or” in python
问题 Is it considered bad style to assign values to variables like this? x = "foobar" or None y = some_variable or None In the above example, x gets the value 'foobar'. 回答1: No, it's a common practice. It's only considered bad style for expressions that are considerably longer than yours. 回答2: The primary danger of doing something like this is the possibility that (in the second case) some_variable is False but not None (the integer 0 , for instance) and you don't want to end up with y equal to