You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# If/ Else conditions are used to decide to do something based on something being true or false
x=21
y=20
# Comparison Operators (==, !=, >, <, >=, <=) - Used to compare values
# Simple if
ifx>y:
print(f'{x} is greater than {y}')
# If/else
ifx>y:
print(f'{x} is greater than {y}')
else:
print(f'{y} is greater than {x}')
# elif
ifx>y:
print(f'{x} is greater than {y}')
elifx==y:
print(f'{x} is equal to {y}')
else:
print(f'{y} is greater than {x}')
# Nested if
ifx>2:
ifx<=10:
print(f'{x} is greater than 2 and less than or equal to 10')
# Logical operators (and, or, not) - Used to combine conditional statements
# and
ifx>2andx<=10:
print(f'{x} is greater than 2 and less than or equal to 10')
# or
ifx>2orx<=10:
print(f'{x} is greater than 2 or less than or equal to 10')
# not
ifnot(x==y):
print(f'{x} is not equal to {y}')
# Membership Operators (not, not in) - Membership operators are used to test if a sequence is presented in an object
numbers= [1,2,3,4,5]
# in
ifxinnumbers:
print(xinnumbers)
# not in
ifxnotinnumbers:
print(xnotinnumbers)
# Identity Operators (is, is not) - Compare the objects, not if they are equal, but if they are actually the same object, with the same memory location: