python Arithmetic Operators 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: ** in python
#** is the exponent symbol in Python, so:
print(2 ** 3)
#output: 8
Example 4: python math operators
# Below follow the math operators that can be used in python
# ** Exponent
2 ** 3 # Output: 8
# % Modulus/Remaider
22 % 8 # Output: 6
# // Integer division
22 // 8 # Output: 2
# / Division
22 / 8 # Output: 2.75
# * Multiplication
3 * 3 # Output: 9
# - Subtraction
5 - 2 # Output: 3
# + Addition
2 + 2 # Output: 4
Example 5: 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 6: arithmetic operators in python
Arithmetic operators: Arithmetic operators are used to perform mathematical
operations like addition, subtraction, multiplication and division.