← Back to Python

All Topics

Advertisement

Learn/Python/Python Fundamentals

Operators in Python

Topic: Basics

Advertisement

Introduction

Operators are special symbols that perform operations on values and variables.

Arithmetic Operators

a, b = 10, 3

print(a + b)   # Addition: 13
print(a - b)   # Subtraction: 7
print(a * b)   # Multiplication: 30
print(a / b)   # Division: 3.333...
print(a // b)  # Floor Division: 3
print(a % b)   # Modulus: 1
print(a ** b)  # Exponentiation: 1000

Comparison Operators

x, y = 5, 10

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

Logical Operators

a, b = True, False

print(a and b)  # False
print(a or b)   # True
print(not a)    # False

Practice Problems

  1. Calculate compound interest with operators
  2. Check if a number is divisible by both 3 and 5
  3. Use operator precedence to evaluate complex expressions
  4. Compare strings lexicographically
  5. Implement a simple calculator using operators

Advertisement

Advertisement

Need More Practice?

Get personalized Python help from ChatWhole's AI-powered platform.

Get Expert Help →