+
)The addition operator is used to add two numeric values. It also works with strings (concatenation) and lists (merging).
Real-time Example: Used in billing systems to calculate total price of items in a shopping cart.
-
)Subtracts the right-hand value from the left-hand value. It is useful for computing differences, reductions, or remaining amounts.
Real-time Example: Used to calculate how much discount to deduct from the original price.
*
)Multiplies two values. It is very commonly used in scenarios like calculating total cost based on quantity and unit price.
Real-time Example: In e-commerce apps, to compute subtotal by multiplying item quantity with unit price.
/
)Divides one value by another and returns a float result. It's widely used in financial or statistical calculations.
Real-time Example: Splitting the bill amount equally among friends at a restaurant.
//
)Returns the largest whole number result of division (removes the decimal part). Common in packing or batch processes.
Real-time Example: Finding how many full boxes of items can be packed when each box holds fixed quantity.
%
)Gives the remainder after division. It's helpful in checking divisibility or even/odd validation.
Real-time Example: Checking whether a roll number is even (assign to Group A) or odd (assign to Group B).
**
)Raises the left value to the power of the right value. Often used in mathematical and financial calculations.
Real-time Example: Used to compute compound interest or exponential growth rates.
==
)Checks whether two values are equal. Returns True
if both values are the same.
Real-time Example: Validating user login credentials by comparing input with stored values.
!=
)Returns True
if the values on both sides are different.
Real-time Example: Detecting incorrect OTP entry.
>
)Returns True
if the left value is greater than the right.
Real-time Example: Checking if a student's marks exceed the passing mark.
<
)Returns True
if the left value is smaller than the right.
Real-time Example: Determining if temperature is below freezing point.
>=
)Returns True
if the left value is greater than or equal to the right value.
Real-time Example: Checking if a purchase is eligible for free shipping.
<=
)Returns True
if the left value is less than or equal to the right.
Real-time Example: Limiting number of login attempts in a web application.
and
)The and
operator returns True
only if both conditions are true. It is commonly used in decision-making processes where multiple criteria must be satisfied.
Real-time Example: Allowing a person to drive only if they are above 18 and have a valid license.
or
)The or
operator returns True
if at least one of the conditions is true. This is used when any one of the options is acceptable.
Real-time Example: Allowing a customer to pay via card or UPI (any one method is enough).
not
)The not
operator inverts the Boolean value of the condition. If the condition is true, not
makes it false, and vice versa. This is used to exclude a condition.
Real-time Example: Blocking access to a page for users who are not logged in.
in
OperatorThe in
operator checks if a value exists in a sequence like a string, list, tuple, dictionary, or set. It returns True
if the item is present.
Real-time Example: Checking if a user’s input is among a list of valid choices.
not in
OperatorThe not in
operator returns True
if the value is not found in a sequence. It’s used to filter out unwanted or restricted data.
Real-time Example: Blocking a login attempt if the username is on the blacklist.
is
OperatorThe is
operator checks whether two variables refer to the same object in memory (identity), not just equality. It returns True
if both variables point to the exact same object.
Real-time Example: Checking if a variable is actually None
(used in many default parameter checks).
is not
OperatorThe is not
operator checks if two variables do not refer to the same object in memory. It’s often used for null-checking or ensuring independence between two references.
Real-time Example: Ensuring a request has actual content before processing.
=
)Assigns the value on the right to the variable on the left. It's the most common operator to create and update variables.
Real-time Example: Assigning the price of a product to a variable.
+=
)Increments the variable by a value and stores the result back. It's a shortcut for x = x + y
.
Real-time Example: Increasing total score after a level in a game.
-=
)Decreases the variable by a value and updates it. It’s a shortcut for x = x - y
.
Real-time Example: Reducing balance after a payment.
*=
)Multiplies and updates the variable. Used when scaling values.
Real-time Example: Doubling the quantity of items.
/=
)Divides and updates the variable. The result will be a float.
Real-time Example: Halving the budget.
%=
)Updates a variable with the remainder of its current value divided by another.
Real-time Example: Checking leftover seats after dividing by rows.