This set of Python Multiple Choice Questions & Answers (MCQs) focuses on “Basic Operators”.
1. Which is the correct operator for power(xy) in Python?
a) x^y
b) x**y
c) x^^y
d) None of the mentioned
View Answer
Explanation: In python, the power operator is x**y. For example, 2**3=8 results in 8.
2. Which one of these is floor division?
a) /
b) //
c) %
d) None of the mentioned
View Answer
Explanation: The // operator in Python performs floor division, which returns the largest integer less than or equal to the division result. For example, 5 // 2 results in 2, not 2.5. The / operator, on the other hand, performs true division and returns a float (5 / 2 = 2.5). To get the integer result without the fractional part, use //.
3. What is the order of precedence in python?
i) Parentheses
ii) Exponential
iii) Multiplication
iv) Division
v) Addition
vi) Subtraction
a) i,ii,iii,iv,v,vi
b) ii,i,iii,iv,v,vi
c) ii,i,iv,iii,v,vi
d) i,ii,iii,v,vi,iv
View Answer
Explanation: Python follows the PEMDAS rule (similar to BODMAS): Parentheses, Exponentiation, Multiplication/Division, then Addition/Subtraction. Operators at the same level are evaluated left to right.
4. What is the answer to this expression, 22 % 3 is?
a) 7
b) 1
c) 0
d) 5
View Answer
Explanation: The modulus operator (%) returns the remainder when one number is divided by another. In this case, 22 % 3 gives the remainder 1 (since 22 divided by 3 is 7 with a remainder of 1).
5. Can mathematical operations be directly performed on a string in Python without conversion?
a) True
b) False
View Answer
Explanation: In Python, you cannot perform mathematical operations like addition, subtraction, multiplication, or division directly on a string. To perform arithmetic operations, you must first convert the string to a numerical type (e.g., int or float). Otherwise, Python will raise a TypeError.
6. Operators with the same precedence are evaluated in which manner?
a) Left to Right
b) Right to Left
c) Can’t say
d) None of the mentioned
View Answer
Explanation: In Python language, most of the operators with the same precedence are evaluated with left to right such as a lot of binary operators. However, exponent operator, unary operators, ternary, and assignment operators are evaluated from right to left.
7. What is the output of this expression, 3*1**3?
a) 27
b) 9
c) 3
d) 1
View Answer
Explanation: In Python, the exponentiation operator (**) has higher precedence than multiplication (*). Therefore, the expression is evaluated as 1 ** 3 first, which equals 1. Then, 3 * 1 is evaluated, giving the final result of 3.
8. Which one of the following has the same precedence level?
a) Addition and Subtraction
b) Multiplication, Division and Addition
c) Multiplication, Division, Addition and Subtraction
d) Addition and Multiplication
View Answer
Explanation: In Python, Addition (+) and Subtraction (-) operators have the same precedence level. Similarly, Multiplication (*) and Division (/) operators also share the same precedence level, but they are evaluated before addition and subtraction due to their higher precedence.
9. The expression int(x) implies that the value of variable x is converted to integer.
a) True
b) False
View Answer
Explanation: The expression int(x) explicitly converts the value of variable x to the integer data type. This is an example of explicit type conversion in Python.
10. Which one of the following has the highest precedence in the expression?
a) Exponential
b) Addition
c) Multiplication
d) Parentheses
View Answer
Explanation: The Parentheses () have the highest precedence in Python, followed by Exponentiation **, then Multiplication and Division, and finally Addition and Subtraction. This order is known as PEMDAS (Parentheses, Exponentiation, Multiplication/Division, Addition/Subtraction).
Sanfoundry Global Education & Learning Series – Python.
To practice all areas of Python, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Apply for Python Internship
- Check Information Technology Books
- Check Python Books
- Practice Programming MCQs
- Apply for Programming Internship