-
Hajipur, Bihar, 844101
Operators are special symbols in Python used to perform operations on variables and values.
For example, +
is an operator used to add two values.
Python provides several types of operators:
Type | Example Operators |
---|---|
Arithmetic | + , - , * , / , // , % , ** |
Assignment | = , += , -= , *= , /= , etc. |
Comparison | == , != , > , < , >= , <= |
Logical | and , or , not |
Identity | is , is not |
Membership | in , not in |
Bitwise | & , ` |
Operator | Meaning |
---|---|
+ |
Addition |
- |
Subtraction |
* |
Multiplication |
/ |
Division |
// |
Floor Division |
% |
Modulus |
** |
Exponentiation |
Used to assign values to variables:
=
, +=
, -=
, *=
, /=
, %=
, //=
, **=
, etc.
Example:
x = 10
x += 5 # Now x becomes 15
Used to compare two values and return True
or False
.
Operator | Meaning |
---|---|
== |
Equal to |
!= |
Not equal to |
> |
Greater than |
< |
Less than |
>= |
Greater or equal |
<= |
Less or equal |
Used to combine conditional statements.
Operator | Description |
---|---|
and |
True if both are true |
or |
True if at least one is true |
not |
Reverses the result |
Used to compare memory locations.
Operator | Meaning |
---|---|
is |
Returns True if both variables point to the same object |
is not |
Returns True if they do not |
Used to check if a value is in a sequence (list, string, etc.)
Operator | Meaning |
---|---|
in |
True if present |
not in |
True if not present |
Works on binary numbers.
Operator | Name |
---|---|
& |
AND |
` | ` |
^ |
XOR |
~ |
NOT |
<< |
Left Shift |
>> |
Right Shift |
Q1. Write a Python program to add two numbers using the +
operator.
Q2. Write a Python program to subtract one number from another using the -
operator.
Q3. Write a Python program to multiply two numbers using the *
operator.
Q4. Write a Python program to divide two numbers using both /
and //
operators and observe the difference in the output.
Q5. Write a Python program to use the **
operator to calculate the square of a number.
Q6. Write a Python program to check if two values are equal using the ==
operator.
Q7. Write a Python program to use the and
operator to check if two conditions are true.
Q8. Write a Python program to use the in
operator to check if a word exists in a string.
Q9. Write a Python program to use the is
operator to check if two variables refer to the same object.
Q10. Write a Python program to perform bitwise AND on two integers using the &
operator.
Q1: Which operator is used for exponentiation in Python?
Q2: What does the // operator do?
Q3: Which operator is used to check equality?
Q4: What is the output of True and False?
Q5: Which operator is used to check membership in a list?
Q6: What does is operator compare?
Q7: What is the result of not True?
Q8: Which of the following is a bitwise operator?
Q9: What does the % operator return?
Q10: Which operator increases a variable’s value by another?