print(10==10)# Checks if 10 = 10 --> will print True# String comparisonprint('hello'=='Hello')# Checks if hello = Hello --> will print False
Comparison 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 Trueprint(5=5.01)# Checks if 5 = 5.01 --> will print False
Less then, greater then, less then or equal to, grater then or equal to:
print(5<10)# Checks if 5 < 10 --> will print Trueprint(5>10)# Checks if 5 > 10 --> will print Falseprint(5<=5)# Checks if 5 less then or equal to 5 --> will print Trueprint(5>=10)# Checks if 5 greater then or equal to 10 --> will print False
The bang operator - (Negation operator):
print(5!=6)# Checks is 5 is NOT equal to 6 --> will print True
The 'or' condition:
print('hello'=='Hello'or5==5)# Checks if one of the conditions is correct and if it is it will print True
The 'and' condition:
print('hello'=='Hello'and5==5)# Checks if both conditions are correct, if they are not it will print False
To write this cleaner it is better for each condition to be wrapped in it's own paranthesis:
print(('hello'=='Hello') and (5==5))
Evaluation of statements:
True+True=TrueTrue+False=FalseFalse+False=False
The 'not' operator:
# Not will do the oposite:print( notFalse )# Prints Trueprint(notTrue)# Prints False