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?

  1. when a , b both true.
  2. when else executed, else? opposite of previous if not 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

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -