Python operators in software development are special symbols or keywords used to perform operations on values and variables. These operations can be arithmetic, comparisons, logical decisions, bit manipulations, assignments, and more.

Learn how software engineering in Abuja

Python groups operators into seven major categories:

  1. Arithmetic Operators
  2. Comparison (Relational) Operators
  3. Logical Operators
  4. Assignment Operators
  5. Bitwise Operators
  6. Membership Operators
  7. Identity Operators

Let’s break each one down with simple examples.

1. Arithmetic Operators

Used for mathematical operations.

OperatorMeaningExample
+Addition3 + 2 → 5
-Subtraction5 - 1 → 4
*Multiplication4 * 3 → 12
/Division10 / 2 → 5.0
%Modulus (remainder)10 % 3 → 1
**Exponentiation2 ** 3 → 8
//Floor division7 // 2 → 3

Example:

a = 7
b = 3

print(a + b)   # 10
print(a % b)   # 1
print(a ** b)  # 343

2. Comparison Operators

Used to compare values. They return True or False.

OperatorMeaningExample
==Equal to5 == 5 → True
!=Not equal5 != 3 → True
>Greater than4 > 2 → True
<Less than3 < 1 → False
>=Greater or equal4 >= 4 → True
<=Less or equal2 <= 3 → True

Example:

x = 10
y = 20

print(x < y)   # True
print(x == y)  # False

3. Logical Operators

Used for boolean logic operations.

OperatorMeaning
andTrue if both conditions are true
orTrue if at least one is true
notNegates a boolean

Example:

x = 5
print(x > 2 and x < 10)  # True
print(x < 2 or x == 5)   # True
print(not(x == 5))       # False

4. Assignment Operators

Used to assign values and perform compound assignment.

OperatorMeaningExample
=Assignx = 10
+=Add and assignx += 3
-=Subtract and assignx -= 2
*=Multiply and assignx *= 4
/=Divide and assignx /= 2
%=Modulus assignx %= 3
**=Power assignx **= 2
//=Floor divide assignx //= 3

Example:

x = 10
x += 5  # x = x + 5
print(x)  # 15

5. Bitwise Operators

Used to perform operations on binary numbers.

OperatorMeaningExample
&AND5 & 3 → 1
``OR
^XOR5 ^ 3 → 6
~NOT~5 → -6
<<Left shift5 << 1 → 10
>>Right shift5 >> 1 → 2

Example:

a = 5   # 101 in binary
b = 3   # 011 in binary
print(a & b)  # 1
print(a | b)  # 7

6. Membership Operators

Check if a value exists in a sequence (list, string, tuple).

OperatorMeaning
inTrue if value is present
not inTrue if value is not present

Example:

nums = [1, 2, 3, 4]
print(3 in nums)        # True
print(5 not in nums)    # True

7. Identity Operators

Check if two variables reference the same object in memory.

OperatorMeaning
isTrue if identical objects
is notTrue if not identical

Example:

a = [1, 2]
b = a
c = [1, 2]

print(a is b)      # True (same object)
print(a is c)      # False (same content, different object)

Summary

Python operators allow you to:

  • Do math operations
  • Compare values
  • Combine conditions
  • Manipulate bits
  • Assign values efficiently
  • Test membership and identity

They form the foundation of logical and mathematical operations in Python programming.

Recent Posts

JavaScript Memoization

In JavaScript, it’s commonly used for: Recursive functions (like Fibonacci) Heavy calculations Repeated API/data processing…

2 weeks ago

CSS Container Queries: Responsive Design That Actually Makes Sense

For years, responsive design has depended almost entirely on media queries. We ask questions like: “If…

2 weeks ago

Cron Jobs & Task Scheduling

1. What is Task Scheduling? Task scheduling is the process of automatically running commands, scripts,…

2 weeks ago

Differences Between a Website and a Web App

Here’s a comprehensive, clear differentiation between a Website and a Web App, from purpose all the…

3 weeks ago

Essential VS Code Extensions Every Developer Should Use

Visual Studio Code (VS Code) is powerful out of the box, but its real strength…

1 month ago

JavaScript Variables

1. What Is a Variable in JavaScript? A variable is a named container used to store data…

1 month ago