0

Conditions and loops (python)

How to set up a condition which only works when the other conditions are false for all instances (elements ) of the iterable .

24th Mar 2021, 10:36 AM
Max Lwe
Max Lwe - avatar
6 odpowiedzi
+ 2
if all(not [instance condition(s)] for instance in iterable): # do stuff if all [instance condition(s)] are false
24th Mar 2021, 12:40 PM
visph
visph - avatar
+ 2
if elif elif ... else <--- this one runs when all others don't pass. you could call it the default.
24th Mar 2021, 10:43 AM
Slick
Slick - avatar
0
Thanks that is what i was looking for.
24th Mar 2021, 4:48 PM
Max Lwe
Max Lwe - avatar
0
the square brackets no. however you could use parenthesis (round brackets) to enclose your conditionnal expressions ;)
24th Mar 2021, 5:08 PM
visph
visph - avatar
0
edited my answer to remove the unexpected 'if' ^^
24th Mar 2021, 5:51 PM
visph
visph - avatar
- 1
Are the brackets part of the code?
24th Mar 2021, 5:05 PM
Max Lwe
Max Lwe - avatar