, , , 1 " False, " " b " ", , , , ? - ?
, . condition and if-true or if-false - , > 2.5, , condition ? if-true : if-false if-true if condition else if-false.
, if-true - , false ("", [], (), False 0)), , , , , if-true false.
condition and a or b a ("", ), (1) true, 1 and a False, b.
The solution to this problem is to either use Python 2.5+ ( if-true if condition else if-false) syntax or make sure that it is if-truenever false. One way to perform the second - pack if-trueand if-falsein a tuple or a list, as a non-empty iterabel always always:
>>> a = ""
>>> b = "second"
>>> condition = 1
>>> condition and a or b
'second'
>>> condition and [a] or [b]
['']
>>> (condition and [a] or [b])[0]
''
This is a kind of ugly solution, but it is there if you need to orient old versions of Python.