Comparison Operators
Comparison Operators
= - is used for assignment
== - is used for comparison
print(10 == 10) # Checks if 10 = 10 --> will print True
# String comparison
print('hello' == 'Hello') # Checks if hello = Hello --> will print FalseComparison operators take into consideration types as well:
print(5 == '5') # Checks if 5 = '5' --> will print False
# There are also certain types that are 'truthy' (kinda true)
print(5 = 5.00) # Checks if 5 = 5.00 --> will print True
print(5 = 5.01) # Checks if 5 = 5.01 --> will print FalseLess then, greater then, less then or equal to, grater then or equal to:
print(5 < 10) # Checks if 5 < 10 --> will print True
print(5 > 10) # Checks if 5 > 10 --> will print False
print(5 <= 5) # Checks if 5 less then or equal to 5 --> will print True
print(5 >= 10) # Checks if 5 greater then or equal to 10 --> will print FalseThe bang operator - (Negation operator):
The 'or' condition:
The 'and' condition:
To write this cleaner it is better for each condition to be wrapped in it's own paranthesis:
Evaluation of statements:
The 'not' operator:
All comparison operators result in a bool value:
bool value:Either True
Either False
Last updated