0
When might someone absolutely have to use a nested conditional?
I’m reading Think Python and it is talking about nested conditionals and chained conditionals and in the text it says to avoid nested conditionals where you can and rewrite it with logical operators so that it’s less confusing. Which brings me to my question… in what sort of situation is using nested conditionals unavoidable? Can anyone provide an example?
3 Antworten
+ 5
if a:
if b:
print("a & b are true")
else:
print("a is true but b is false")
else:
if b:
print("a is false but b is true")
else:
print("a & b are false")
you may see by yourself when you cannot avoid nesting conditonal or simplify the conditional by using 'and' or 'or' in conditions...
+ 1
Thank you both! I think I understand it now.