Whenever I’m coding something that requires a lot of conditionals, I end up doing this:
if foo:
if bar:
if foobar:
if barfoo:
if foobarfoo:
if barfoobar:
# And forever and ever and ever
I can’t write if foo and bar and foobar and ... because I check for the value list elements (if foo[1] == 'bar') inside of an if somewhere down the line, and if the list index don’t exist, I get an error.
Is there a shortcut to conditionally checking things like this, or an alternative method? Thanks.
in python,
andshort circuits. If the left side of the expression is false, the right side is not evaluated at all.