Python Questions and Answers – Basic Operators

This set of Python Multiple Choice Questions & Answers (MCQs) focuses on “Basic Operators”.

1. Which is the correct operator for power(xy)?
a) X^y
b) X**y
c) X^^y
d) None of the mentioned
View Answer

Answer: b
Explanation: In python, power operator is x**y i.e. 2**3=8.

2. Which one of these is floor division?
a) /
b) //
c) %
d) None of the mentioned
View Answer

Answer: b
Explanation: When both of the operands are integer then python chops out the fraction part and gives you the round off value, to get the accurate answer use floor division. This is floor division. For ex, 5/2 = 2.5 but both of the operands are integer so answer of this expression in python is 2. To get the 2.5 answer, use floor division.

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,iv,vi,v
View Answer

Answer: a
Explanation: For order of precedence, just remember this PEMDAS (similar to BODMAS).
advertisement
advertisement

4. What is the answer to this expression, 22 % 3 is?
a) 7
b) 1
c) 0
d) 5
View Answer

Answer: b
Explanation: Modulus operator gives the remainder. So, 22%3 gives the remainder, that is, 1.

5. Mathematical operations can be performed on a string.
a) True
b) False
View Answer

Answer: b
Explanation: You can’t perform mathematical operation on string even if the string is in the form: ‘1234…’.

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

Answer: a
Explanation: None.

7. What is the output of this expression, 3*1**3?
a) 27
b) 9
c) 3
d) 1
View Answer

Answer: c
Explanation: First this expression will solve 1**3 because exponential has higher precedence than multiplication, so 1**3 = 1 and 3*1 = 3. Final answer is 3.
advertisement

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

Answer: a
Explanation: “Addition and Subtraction” are at the same precedence level. Similarly, “Multiplication and Division” are at the same precedence level. However, Multiplication and Division operators are at a higher precedence level than Addition and Subtraction operators.

9. The expression Int(x) implies that the variable x is converted to integer.
a) True
b) False
View Answer

Answer: a
Explanation: Int(x) converts the datatype of the variable to integer and is the example of explicit data conversion.
advertisement

10. Which one of the following has the highest precedence in the expression?
a) Exponential
b) Addition
c) Multiplication
d) Parentheses
View Answer

Answer: d
Explanation: Just remember: PEMDAS, that is, Parenthesis, Exponentiation, Division, Multiplication, Addition, Subtraction. Note that the precedence order of Division and Multiplication is the same. Likewise, the order of Addition and Subtraction is also the same.

Sanfoundry Global Education & Learning Series – Python.

To practice all areas of Python, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.