language = 'Python'
if language == 'Python':
print('Conditional was True')
'''
out:
Conditional was True
'''
here are the comparisons:
# Comparisons:
# Equal: ==
# Not Equal: !=
# Greater Than: >
# Less Than: <
# Greater or Equal: >=
# Less or Equal: <=
# Object Identity: is
language = 'Python'
if language == 'Python':
print('Language is Python')
else:
print('No match')
'''
out:
Language is Python
'''
language = 'Java'
if language == 'Python':
print('Language is Python')
else:
print('No match')
'''
out:
No match
'''
language = 'Java'
if language == 'Python':
print('Language is Python')
elif language == 'Java':
print('Language is Java')
else:
print('No match')
'''
out:
Language is Java
'''
user = 'Admin'
logged_in = True
if user == 'Admin' and logged_in:
print('Admin Page')
else:
print('Bad Creds')
'''
out:
Admin Page
'''
##################
user = 'Admin'
logged_in = False
if user == 'Admin' or logged_in:
print('Admin Page')
else:
print('Bad Creds')
'''
out:
Bad Creds
'''
##################
user = 'Admin'
logged_in = False
if not logged_in:
print('Please log in')
else:
print('Welcome')
'''
out:
Please log in
'''
a = [1,2,3]
b = [1,2,3]
print(a == b) # True
print(a is b) # False, cause it's two different objects in memory
# check id
print(id(a))
print(id(b))
'''
out:
True
False
4492373248
4492373184
'''
##################
a = [1,2,3]
b = a
print(a == b)
print(a is b)
# check id
print(id(a))
print(id(b))
'''
out:
True
True
4489997376
4489997376
'''
# False Values
# False
# None
# Zero of any numeric type
# Any empty sequence. For example, '', (), [].
# Any empty mapping. For example, {}.