

Operator
Operation
Example
+
Addition
10 + 5
-
Subtraction
10 - 5
*
Multiplication
10 * 5
/
Division
10 / 5
%
Modulus
10 % 3
//
Floor Division
10 // 3
**
Exponentiation
2 ** 3
Python operators are special symbols and keywords used to perform a variety of operations on values and variables. These operators are essential components of the Python programming language, enabling you to carry out arithmetic calculations, compare values in terms of equality or inequality, assign distinct data to variables, combine complex conditions in logical statements, and thoroughly check relationships between different objects.
Mastering the use of operators is fundamental for developing efficient algorithms and writing clean, effective code in your programming projects.
Operators in Python
The addition operator adds numeric values together, allowing for the combination of different quantities. This mathematical operation is fundamental in various calculations and is widely used in programming and data manipulation to generate new results from existing numbers.
Input
a = 15
b = 10
print(a + b)
Output
Example
first_name = "Amit"
last_name = "Sharma"
full_name = first_name + " " + last_name
print(full_name)
25
1. Addition Operator (+)
The + operator can also concatenate, or join, strings together, allowing you to create longer, more complex messages by combining multiple pieces of information into a single output. This feature is particularly useful when you want to display dynamic content or craft cohesive sentences from different data points.
Output
Amit Sharma
The subtraction operator removes one numeric value from another, effectively determining the difference between the two. This fundamental operation is crucial in various mathematical calculations, allowing us to solve for unknowns and analyze numerical data in diverse fields such as finance, engineering, and science.
Input
Explanation
total_marks = 100
obtained_marks = 85
remaining_marks = total_marks - obtained_marks
print(remaining_marks)
Output
The result shows how many marks are left after subtracting the obtained marks from the total marks.
15
2. Subtraction Operator (-)
The multiplication operator is used to multiply numbers, which means that when you have a number, you can increase it by repeated addition of another number, allowing for a variety of mathematical calculations and applications in different fields such as science, engineering, and finance.
Input
Explanation
price = 250
quantity = 4
total = price * quantity
print(total)
Output
This type of calculation is commonly used in various programs and applications that calculate product prices, quantities, measurements, and totals.
These calculations are essential for accurately determining the costs associated with purchasing items, managing inventories, and conducting various types of statistical analyses. By employing such calculators, individuals and businesses can ensure that they optimize their financial transactions and maintain precise records of their inventory and sales.
1000
3. Multiplication Operator (*)
The division operator divides one value by another. In Python, / normally produces a floating-point result. This means that when you divide two integers, the result will still represent a decimal value if necessary, providing greater accuracy in mathematical operations. This flexibility allows for more precise calculations in programming and enables developers to handle a variety of mathematical scenarios effectively.
Input
Explanation
total = 100
students = 4
average = total / students
print(average)
Output
Even though the result is mathematically 25, Python displays it as 25.0 because the / operator returns a floating-point value.
25.0
4. Division Operator (/)
The modulus operator returns the remainder left after a division operation, providing a way to determine what's left over when one number is divided by another. This operator is particularly useful in programming and mathematical calculations, as it helps in generating values for various applications such as ensuring even distributions or identifying patterns when dealing with integers.
Input
Explanation
number = 17
remainder = number % 5
print(remainder)
Output
When 17 is divided by 5, the remainder is 2.
2
5. Modulus Operator (%)
The floor division operator divides two numbers and returns the floor of the result.
Input
Explanation
Output
This is useful when you need the number of complete groups or units that can be formed from a division.
3
6. Floor Division Operator (//)
total_items = 17
boxes = 5
full_boxes = total_items // boxes
print(full_boxes)
The exponentiation operator raises a number to a specified power, allowing for calculations that involve powers and roots that are crucial in various mathematical and scientific applications. By using this operator, one can efficiently compute large numbers raised to significant powers, thus facilitating advanced problem-solving in fields such as finance, engineering, and physics.
Explanation
Output
The expression 2 ** 4 means:
2 × 2 × 2 × 2 = 16
16
7. Exponentiation Operator (**)
Input
base = 2
power = 4
result = base ** power
print(result)
Assignment operators are employed to either assign values to variables or to update pre-existing values.
Operator
Example
Meaning
=
x = 10
Assign a value
+=
x += 5
Add and assign
-=
x -= 5
Subtract and assign
*=
x *= 5
Multiply and assign
/=
x /= 5
Divide and assign
%=
x %= 5
Modulus and assign
//=
x //= 5
Floor divide and assign
**=
x **= 2
Exponentiate and assign
8. Assignment Operators
Input
Explanation
60
The statement:
score += 10
is a shorter form of:
score = score + 10
These operators are especially useful when a variable needs to be updated repeatedly.
Output
score = 50
score += 10
print(score)
9. Comparison Operators
Operator
Meaning
==
Equal to
!=
Not equal to
>
Greater than
<
Less than
>=
Greater than or equal to
<=
Less than or equal to
Output
Exaplanation
Output
marks = 75
print(marks >= 40)
True
Input
Exaplanation
False
Comparison operators are frequently used with if statements to make decisions in Python programs.
age = 16
print(age >= 18)
Input
Comparison operators are essential tools in programming and mathematics, used to compare two values effectively. When you apply these operators, the result of the comparison yields a Boolean value, which can be either True or False. Understanding how these operators work is crucial for controlling the flow of logic within your code. This knowledge enables developers to evaluate conditions and make decisions based on the results of these comparisons, leading to dynamic and responsive applications.
Because 75 is greater than 40, the comparison evaluates to True.
10. Logical Operators
and
or
not
Returns true when the required conditions are true
Returns true when at least one condition is true
Reverses a Boolean result
1. and Operator
Input
Output
True
Explanation
Both conditions evaluate to True, so the complete expression is True.
Logical operators are used to combine or modify conditions.
Python provides three logical operators:
age = 25
has_id = True
print(age >= 18 and has_id)
2. or Operator
Input
day = "Sunday"
print(day == "Saturday" or day == "Sunday")
Output
Explanation
True
Only one of the conditions needs to be true for this expression to produce True.
3.not Operator
Input
Explanation
Output
is_closed = False
print(not is_closed)
True
The not operator reverses the Boolean value.
Identity operators determine whether two references point to the same object in memory.
Explanation
Output
Important: is checks object identity, while == checks whether two values are equal. They should not be treated as interchangeable.
True
11. Identity Operators
Input
value = None
print(value is None)
Python provides two identity operators:
is
is not
The is operator is commonly used when checking whether a value is None.
12. Membership Operators
Output
Exaplanation
Output
fruits = ["Apple", "Mango", "Banana"] print("Mango" in fruits)
True
Input
Exaplanation
True
The expression returns True because "Orange" does not exist in the list.
fruits = ["Apple", "Mango", "Banana"] print("Orange" not in fruits)
Input
Membership operators check whether a value exists within a collection or sequence such as a string, list, tuple, or set.
Since "Mango" is present in the list, the expression returns True.
Python provides:
in
not in
Using in
Using not in
13. Bitwise Operators
Operator
Name
&
Bitwise AND
|
Bitwise OR
^
Bitwise XOR
~
Bitwise NOT
<<
Left Shift
>>
Right Shift
Input
Output
a = 6
b = 3
print(a & b)
2
Explanation
The & operator performs a bitwise AND operation on the binary representations of the two integers.
Bitwise operators perform operations on the binary representation of integers. They are useful in areas such as low-level programming, flags, embedded systems, and certain data-processing tasks.
14. Operator Precedence in Python
Output
Exaplanation
Output
result = 10 + 5 * 2
print(result)
20
Input
Exaplanation
30
Here, Python calculates 10 + 5 first and then multiplies the result by 2.
result = (10 + 5) * 2
print(result)
Input
When multiple operators appear in the same expression, Python follows a defined order of precedence to determine which operation is performed first.
Parentheses can be used when you want to control the order of evaluation.
Using Parentheses
Multiplication has higher precedence than addition, so Python evaluates the expression as:
5 * 2 = 10
10 + 10 = 20
Contact
Reach out for AI courses and support
Phone
careers@ahkacademy.in
Mo:- +91-7769920076
}
© 2025. All rights reserved.