0% found this document useful (0 votes)
3 views2 pages

Python Operators Practice Questions

The document contains practice questions and solutions for Python operators, including arithmetic, comparison, logical, bitwise, and string concatenation operators. Each question provides a code snippet demonstrating the use of specific operators with examples. The document serves as a resource for learning and practicing Python operator functionalities.

Uploaded by

dk041202
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Python Operators Practice Questions

The document contains practice questions and solutions for Python operators, including arithmetic, comparison, logical, bitwise, and string concatenation operators. Each question provides a code snippet demonstrating the use of specific operators with examples. The document serves as a resource for learning and practicing Python operator functionalities.

Uploaded by

dk041202
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Operators Practice Questions with Solutions

1. You have two variables, `a` and `b`, containing integer values. Use arithmetic operators to calculate and pr

a = 10
b = 5
print('Sum:', a + b)
print('Difference:', a - b)
print('Product:', a * b)
print('Quotient:', a / b)

2. Given a variable `x` containing an integer value, use the modulus operator to check if `x` is even or odd.

x = 7
print('Even' if x % 2 == 0 else 'Odd')

3. You have two variables, `a` and `b`. Use comparison operators to check if `a` is greater than `b`, and print

a = 8
b = 6
print('a > b:', a > b)

4. Given two boolean variables, `p` and `q`, use logical operators to evaluate and print the result of `p AND q

p = True
q = False
print('p and q:', p and q)
print('p or q:', p or q)
print('not p:', not p)

5. You have a variable `n` containing an integer value. Use the bitwise AND, OR, and XOR operators to perfor

n = 6
m = 3
print('AND:', n & m)
print('OR:', n | m)
print('XOR:', n ^ m)

6. Given a variable `y` containing a floating-point number, use the floor division operator to divide `y` by 2 an

y = 9.7
print('Floor Division:', y // 2)

7. You have two strings, `str1` and `str2`. Use the concatenation operator to join these strings and print the r

str1 = 'Hello'
str2 = 'World'
print(str1 + ' ' + str2)

8. Given a variable `z` containing an integer, use the increment operator to increase its value by 1 and print t

Page 1
Python Operators Practice Questions with Solutions

z = 10
z += 1
print('Incremented:', z)

9. You have a list `my_list` and a value `val`. Use the `in` operator to check if `val` is present in `my_list` and

my_list = [1, 2, 3, 4]
val = 3
print(val in my_list)

10. Given two variables `a` and `b`, use the assignment operator to assign the value of `b` to `a` and print `a`.

a = 5
b = 9
a = b
print('a =', a)

Page 2

You might also like