Python/Basics of Python Language

Python Operators

Updated on February 16, 2026
2 min read

Operators are symbols or keywords used to perform operations on values and variables. They tell Python what action to perform, such as adding numbers, comparing values, or checking conditions. Without operators, a program would not be able to calculate, decide, or manipulate data.

Every Python program uses operators to transform input into meaningful output.

Types of Operators in Python

Python provides several types of operators, each serving a specific purpose.

Arithmetic Operators

These operators are used to perform mathematical calculations.

OperatorMeaning
+Addition
-Subtraction
*Multiplication
/Division
%Modulus (remainder)
**Power
//Floor division

Example:

a = 10
b = 3
print(a + b)   # Output:3
print(a % b)   # Output:1

Comparison (Relational) Operators

These operators compare two values and return either True or False.

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

Example:

x = 10
y = 20
print(x < y)  # Output:True

Logical Operators

These operators are used to combine conditions.

OperatorMeaning
andTrue if both are true
orTrue if at least one is true
notReverses the result

Example:

age = 20
print(age > 18 and age < 30) # Output:True

Assignment Operators

These operators assign values to variables.

OperatorMeaning
=Assign
+=Add and assign
-=Subtract and assign
*=Multiply and assign

Example:

x = 10
x += 5

Membership Operators

Used to check whether a value exists in a sequence.

OperatorMeaning
inFound in sequence
not inNot found

Example:

fruits = ["apple", "banana"]
print("apple" in fruits)   # Output:True

Identity Operators

Used to compare memory location of objects.

OperatorMeaning
isSame object
is notDifferent object

Example:

a = [1,2]
b = a
print(a is b)    # Output:True

Got it. Then let’s do it properly, clean, exact, and interview-safe.

Bitwise Operators

Bitwise operators work on binary representations (bits) of numbers.

They operate bit by bit, not on whole values like logical operators.

OperatorMeaning
&AND – Sets bit to 1 if both bits are 1
|OR – Set bit to 1 if one or both bits are 1
^XOR – Sets bit to 1 if bits are different
~NOT – Inverts all bits
<<Left shift – Shifts bits to the left
>>Right shift – Shifts bits to the right

Example

a = 10
b = 3

print(a & b)  # Output:2

Explanation:

Binary representation:

101010
 30011
------------
&0010

0010 in decimal is 2.

So, the output will be:

2

Key insight (this is where most people fail)

  • Logical operators (and, or) work on truth values
  • Bitwise operators (&, |) work on bits

Confusing them means you don’t understand how data actually lives in memory.

Conclusion

Operators are the tools that make Python useful. They allow programs to calculate, compare, and make decisions. Without operators, Python would only store data—it would never do anything meaningful with it.