Python Operators

  • + Addition
  • - Subtraction
  • * Multiplication
  • / Division
  • % Modulo

Two Integers

Output



50 <class 'int'>
Code
x = 5
y = 10
z = x * y
print(z)
print(type(z))

Division - Always Float

Output




3.0 <class 'float'>

2.25 <class 'float'>
Code
a = 9
b = 3
c = 4
x = a / b
print(x)
print(type(x))
print()
y = a / c
print(y)
print(type(y))

Two Floats

Output



7.0 <class 'float'>
Code
a = 2.5
b = 4.5
c = a + b
print(c)
print(type(c))

Mixed - Always Float

Output



3.0 <class 'float'>
Code
a = 5
b = 2.0
c = a - b
print(c)
print(type(c))

Python Operators

  • + Addition
  • - Subtraction
  • * Multiplication
  • / Division
  • % Modulo
  • ** Exponentiation
  • // Integer Division

Exponentiation

Output

125 <class 'int'>
Code
x = 5 ** 3
print(x)
print(type(x))

Integer Division

Output

3.0 <class 'float'>
Code
a = 17.5 // 4.5
print(a)
print(type(a))

Order of Operations

  1. Parentheses
  2. Exponentiation
  3. Multiplication, Division,
    Integer Division, Modulo
  4. Addition, Subtraction