Skip to content

Latest commit

 

History

History

07_operators

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Operators in Python ➕➖✖️➗

In this section, we'll discuss operators in Python, which are symbols or combinations of symbols that perform operations on variables and values. Understanding operators is crucial for working with expressions and performing calculations in Python.

What are Operators? ⚙️

  • Operators are non-alphanumeric characters and combinations of characters that Python uses to perform operations on data.
  • Python recognizes a variety of operators, each with its specific functionality.

List of Common Operators in Python 🔢

Here is a list of the most commonly used operators in Python:

Arithmetic Operators ➕➖✖️➗

  • + : Addition
  • - : Subtraction
  • * : Multiplication
  • / : Division
  • % : Modulus (remainder after division)
  • ** : Exponentiation (power)
  • // : Floor division (division that results in the largest whole number less than or equal to the result)

Example:

a = 10
b = 3

print(a + b)  # 13
print(a - b)  # 7
print(a * b)  # 30
print(a / b)  # 3.3333...
print(a % b)  # 1
print(a ** b) # 1000
print(a // b) # 3

Comparison Operators 🔍

  • < : Less than
  • <= : Less than or equal to
  • > : Greater than
  • >= : Greater than or equal to
  • == : Equal to
  • != : Not equal to

Example:

a = 5
b = 3

print(a < b)   # False
print(a <= b)  # False
print(a > b)   # True
print(a >= b)  # True
print(a == b)  # False
print(a != b)  # True

Summary 📝

Python provides a wide range of operators that you can use for arithmetic calculations, bitwise operations, comparisons, and more. In Python v3, the @ operator was introduced for matrix multiplication, expanding the capabilities of Python in handling mathematical operations efficiently.