Python Operators


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:


🧮 Types of Operators

Type Example Operators
Arithmetic +, -, *, /, //, %, **
Assignment =, +=, -=, *=, /=, etc.
Comparison ==, !=, >, <, >=, <=
Logical and, or, not
Identity is, is not
Membership in, not in
Bitwise &, `

➕ Arithmetic Operators
Operator Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
// Floor Division
% Modulus
** Exponentiation

📝 Assignment Operators

Used to assign values to variables:

  • =, +=, -=, *=, /=, %=, //=, **=, etc.

Example:

x = 10
x += 5   # Now x becomes 15

⚖️ Comparison Operators

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

🤔 Logical Operators

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

🔎 Identity Operators

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

📦 Membership Operators

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

⚙️ Bitwise Operators

Works on binary numbers.

Operator Name
& AND
` `
^ XOR
~ NOT
<< Left Shift
>> Right Shift

Practice Questions

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.


Python Operators Quiz

Q1: Which operator is used for exponentiation in Python?

A. ^
B. **
C. *
D. %

Q2: What does the // operator do?

A. Divide normally
B. Divide and return remainder
C. Floor division
D. None of these

Q3: Which operator is used to check equality?

A. =
B. ==
C. !=
D. :=

Q4: What is the output of True and False?

A. True
B. False
C. Error
D. None

Q5: Which operator is used to check membership in a list?

A. is
B. ==
C. in
D. not

Q6: What does is operator compare?

A. Value of variables
B. Memory location
C. Type of data
D. Length of variables

Q7: What is the result of not True?

A. True
B. False
C. Error
D. None

Q8: Which of the following is a bitwise operator?

A. and
B. or
C. &
D. not

Q9: What does the % operator return?

A. Quotient
B. Power
C. Remainder
D. Float value

Q10: Which operator increases a variable’s value by another?

A. =+
B. +=
C. ++
D. add=

Go Back Top