Aha! Thank you very much!
In python an empty string/list/set/tuple is considered falsy, similar to False, None or 0 (read more here: https://docs.python.org/2/library/stdtypes.html#truth-value-testing)
False
None
0
So if numbers: means that if the numbers list is not empty, then...
if numbers:
numbers
if x is the same as if len(x) > 0 or if x > 0 or if x == True etc.
if x
if len(x) > 0
if x > 0
if x == True
What is this trick of using only the variable name after the if?
if
Loading collection data...
Aha! Thank you very much!
In python an empty string/list/set/tuple is considered falsy, similar to
False
,None
or0
(read more here: https://docs.python.org/2/library/stdtypes.html#truth-value-testing)So
if numbers:
means that if thenumbers
list is not empty, then...if x
is the same asif len(x) > 0
orif x > 0
orif x == True
etc.What is this trick of using only the variable name after the
if
?