Operators in Python

Python supports several categories of operators:

  • Arithmetic: +, -, *, /, %, **, //
  • Comparison: ==, !=, >, <, >=, <=
  • Logical: and, or, not
  • Assignment: =, +=, -=, *=, /=, %=
  • Bitwise: &, |, ^, ~, <<, >>
  • Membership: in, not in
  • Identity: is, is not
Example: x = 10; y = 3; print(x // y) → Output: 3

These operators are essential for building logic in applications like billing systems, inventory management, and data analysis tools.

Operator Precedence

Python evaluates expressions based on precedence rules:

  1. Parentheses ()
  2. Exponentiation **
  3. Unary +, -
  4. Multiplication, Division, Floor, Modulus
  5. Addition, Subtraction
  6. Comparisons
  7. Logical NOT, AND, OR
Example: print(2 + 3 * 4) → Output: 14

Understanding precedence helps avoid logic errors in financial calculations, conditional flows, and automation scripts.

Print Formatting

Python offers multiple formatting styles:

  • Concatenation: print("Hello", name)
  • f-Strings: print(f"Hello {name}")
  • Format Method: "{:,.2f}".format(12345.678)
  • Percent Style: "%s scored %d" % ("Ali", 95)
Example: print(f"Total: PKR {amount:,.0f}") → Output: Total: PKR 125,000

Used in dashboards, receipts, logs, and user interfaces—print formatting ensures clarity and professionalism.

About Python

Python is a high-level, versatile language used in:

  • Web development (Django, Flask)
  • Data science (Pandas, NumPy, Scikit-learn)
  • Automation and scripting
  • AI/ML (TensorFlow, PyTorch)

Use Case: Instagram uses Python for backend services. Spotify uses it for data pipelines. DigiSuite uses it for microbusiness empowerment.

Abilities: Easy syntax, vast libraries, cross-platform, strong community.

Salary Range:

  • Pakistan: PKR 80K–300K/month
  • Gulf: SAR 8K–25K/month
  • US: $70K–150K/year
Python bridges global tech and local impact—ideal for startups, freelancers, and educators.

Topic-Wise Quiz

Select a topic to begin:

(Quiz logic can be embedded here or linked to external modules.)

Python Exercises