compare operator python code example

Example 1: python larger or equal

# To test if something is larger or equal use '>='
5 >= 10
# Output:
# False

Example 2: python exponent operator

#python exponent operator
num = 2
new_num = num**2
#answer would be 4

Example 3: python comparison operators

# Below follow the comparison operators that can be used in python
# == Equal to
42 == 42 # Output: True
# != Not equal to
'dog' != 'cat' # Output: True
# < Less than
45 < 42 # Output: False
# > Greater Than
45 > 42 # Output: True
# <= Less than or Equal to
40 <= 40 # Output: True
# >= Greater than or Equal to
39 >= 40 # Output: False

Example 4: Python Comparison Operator

# Python code to illustrate
# chaining comparison operators
x = 5
print(1 < x < 10)
print(10 < x < 20 )
print(x < 10 < x*10 < 100)
print(10 > x <= 9)
print(5 == x > 4)

Tags:

Css Example