if statement - Python: Check second variable if first variable is True? -
i have script checks bools through if statements , executes code. trying make that:
if variable true, check if b true , execute code if variable false, execute same code mentioned before a simplified version of have this:
if a: if b: print('foo') else: print('foo') is there better way doesn't require me write print('foo') twice?
if not or (a , b): print('foo') let's talk step step: when print('foo') executed?
- when
a,bbothtrue. - when
elseexecuted,else? opposite of previousifnot a.
finally wish display 'foo' in 1 case or other.
edit: alternatively, simplifying logic equation:
note: you might want avoid unless know doing! clarity way better shortness. trust advice! i've been through there! ;)
if not or b: print('foo') because if not a not true, a must true (the second part of or), a , b can simplified in b (because know fact a true in situation, a , b same true , b can drop first part safely).
Comments
Post a Comment