def if_demo(s):
if s == 'Hello' or s == 'Hi':
s = s + ' nice to meet you'
else:
s = s + ' woo hoo!'
return s
bool(True)
bool(False)
# all of the below evaluate to False. Everything else will evaluate to True in Python.
print(bool(None))
print(bool(False))
print(bool(0))
print(bool(0.0))
print(bool([]))
print(bool({}))
print(bool(()))
print(bool(''))
print(bool(range(0)))
print(bool(set()))
# See Logical Operators and Comparison Operators section for more on booleans.
print(10 > 9)
print(10 == 9)
print(10 < 9)
a = True # dont forget capital T and F, it is case sensitive
b = False
if b == True:
print("b is true")
if b:
print("b is true") # this is the shorthand of the above IF statement
if b == False:
print("b is false") # again dont forget True and False are case sensitive
b = True
if b:
print('b is True')
else:
print('b is False')
def a_bigger(a, b):
if a > b and (a - b) >= 2:
return True
else:
return False
## Can all be written as just
## return (a > b and (a - b) >= 2)
In Python 3.x True and False are keywords and will always be equal to 1 and 0.
my_list = []
if not my_list:
print("the list is empty")
# Boolean variables in python just start with a capital letter
True
False
isinstance(x[0], (int, float))