HOME
ABOUT

Operators

Operators

Arithmetic Operators

x = 10
y = 3
print(x + y)  # Addition: 13
print(x - y)  # Subtraction: 7
print(x * y)  # Multiplication: 30
print(x / y)  # Division: 3.333...
print(x % y)  # Modulus: 1
print(x ** y) # Exponentiation: 1000
print(x // y) # Floor division: 3

Comparison Operators

print(x == y) # Equal: False
print(x != y) # Not equal: True
print(x > y)  # Greater than: True
print(x < y)  # Less than: False
print(x >= y) # Greater than or equal: True
print(x <= y) # Less than or equal: False

Logical Operators

a = True
b = False
print(a and b) # AND: False
print(a or b)  # OR: True
print(not a)   # NOT: False

Assignment Operators

x = 5
x += 3  # Equivalent to x = x + 3
x -= 2  # Equivalent to x = x - 2
x *= 4  # Equivalent to x = x * 4
x /= 2  # Equivalent to x = x / 2

Related Articles

  • Introduction to Python
  • Setting Up Python Environment
  • Python Syntax Basics
  • Variables and Data Types
  • Operators
  • Input and Output
  • Control Flow: Conditionals
  • Control Flow: Loops
  • Functions
  • Lists and Tuples
  • Dictionaries and Sets
  • String Manipulation
  • How to execute SQL queries (Select, Update, Insert, Delete) effectively using Python?