In the previous article, you learned how Python programs communicate with the outside world using input and output. Programs can receive information from users, store that information in variables, and display results after processing it. But storing and displaying data alone does not make a program useful.
Once information enters a program, it must be transformed, compared, or evaluated in order to produce meaningful results. A program might calculate totals, check whether a condition is true, combine multiple rules, or update stored values during execution. This is where operators become essential.
Operators are symbols or keywords that tell Python to perform operations on values. They allow programs to manipulate data, evaluate relationships between values, and compute new results from existing information. Without operators, variables would simply hold values without interacting with each other.
Operands and Binary Operations
When Python performs an operation, the values involved are called operands, and the symbol that performs the operation is called the operator.
Consider the following example:
result = 5 + 3Here, 5 and 3 are operands, while + is the operator.
Most operations in Python involve two operands. These are called binary operations because the operator works on two values.
Examples of binary operations include:
10 - 4
6 * 3
7 > 2Each expression contains two operands and an operator that combines them.
Some operators work with only one operand, such as the unary minus (-5) or the logical operator not. However, binary operators appear far more frequently in everyday programming. Understanding this structure helps clarify how Python evaluates expressions.
Arithmetic Operators — Performing Calculations
Arithmetic operators allow programs to perform mathematical calculations. They operate primarily on numeric data such as integers and floating-point numbers.
For example:
price = 100
quantity = 3
total = price * quantity
print(total)Here the multiplication operator * combines the operands price and quantity to produce a new value.
Python provides several arithmetic operators for different types of calculations:
- Addition
+ - Subtraction
- - Multiplication
* - Division
/ - Floor division
// - Modulus
% - Exponentiation
**
These operators appear frequently in real programs, from financial calculations to scientific computing and data processing.
Comparison Operators — Evaluating Relationships
Programs often need to determine relationships between values. Comparison operators allow Python to evaluate whether two operands satisfy a particular condition.
For example:
age = 18
print(age >= 18)This expression checks whether the value of age is greater than or equal to 18. The result of a comparison is always a Boolean value — either True or False.
Python provides several comparison operators:
- Equal to
== - Not equal to
!= - Greater than
> - Less than
< - Greater than or equal to
>= - Less than or equal to
<=
These operators form the foundation of decision-making in programs and are used heavily in conditional logic.
Logical Operators — Combining Conditions
Sometimes a program must evaluate multiple conditions together. Logical operators allow expressions to be combined into more complex rules.
For example:
age = 20
has_ticket = True
print(age >= 18 and has_ticket)In this example, the expression evaluates to True only if both conditions are satisfied.
Python provides three logical operators:
andornot
Logical operators are particularly important when writing conditions that depend on multiple rules or constraints.
Bitwise Operators — Working With Binary Data
While arithmetic and logical operators work with values at a conceptual level, bitwise operators operate directly on the binary representation of integers.
Computers store numbers internally as sequences of bits — combinations of 0 and 1. Bitwise operators allow programs to manipulate those bits directly.
For example:
a = 5
b = 3
print(a & b)To understand this operation, consider the binary representation of the numbers:
5 → 101
3 → 011Applying the AND operation compares each bit:
101
011
---
001The result is 1.
Python provides several bitwise operators:
&— Bitwise AND|— Bitwise OR^— Bitwise XOR~— Bitwise NOT<<— Left shift>>— Right shift
For example:
a = 5
print(a << 1)The left shift operator moves bits to the left, effectively multiplying the value by two.
Bitwise operators are used less frequently in everyday scripting but are important in low-level programming, networking, cryptography, and performance-sensitive systems.
Assignment Operators — Updating Values
Assignment operators store values in variables and allow those values to change during program execution.
The basic assignment operator is =:
count = 10Python also provides shorthand assignment operators that combine an operation with assignment:
count = 10
count += 5This expression increases the value of count by five.
These operators simplify expressions and help keep code concise and readable.
Membership Operators — Checking Containment
Membership operators check whether a value exists within another object such as a string, list, or set.
For example:
name = "Mohan"
print("M" in name)The expression checks whether the character "M" appears in the string.
Python provides two membership operators:
innot in
These operations are commonly used when validating input or searching through collections of data.
Identity Operators — Comparing Object Identity
Identity operators determine whether two variables refer to the same object in memory.
For example:
a = [1, 2, 3]
b = a
print(a is b)The is operator returns True because both variables refer to the same list object.
This is different from equality comparison (==), which checks whether two values are equal rather than whether they reference the same object. Understanding this distinction becomes important when working with mutable objects such as lists and dictionaries.
Operators in Real Programs
Operators appear in nearly every expression within a program.
Arithmetic operators calculate totals, averages, and measurements. Comparison operators evaluate conditions in authentication systems and business rules. Logical operators combine multiple checks into meaningful decisions.
Bitwise operators manipulate binary data in specialized contexts, while assignment operators update values as programs evolve during execution.
Together, these operators allow raw data to be transformed into useful information.
Why Operators Matter
Operators define how values interact within a program. They enable calculations, comparisons, logical reasoning, and state changes.
Every programming concept that follows — conditional statements, loops, and functions — depends on operators to evaluate expressions and determine behavior. Understanding operators therefore means understanding how programs actually process data.
What Comes Next
Now that your program can store data, receive input, display output, and transform information using operators, the next step is learning how programs make decisions based on those results.
In the next article, you will explore Conditional Statements in Python, where programs choose different actions depending on the conditions they evaluate. Because once a program can compare values, it can decide what should happen next.