I would like to print a message if either a or b is empty.
This was my attempt
a = ""
b = "string"
if (a or b) == "":
print "Either a or b is empty"
But only when both variables contain an empty string does the message print.
How do I execute the print statement only when either a or b is an empty string?
The more explicit solution would be this:
if a == '' or b == '':
print('Either a or b is empty')
In this case you could also check for containment within a tuple:
if '' in (a, b):
print('Either a or b is empty')
if not (a and b):
print "Either a or b is empty"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With