Python Quizs Question and Answers – Basic Operators

Q 1. Which is the correct operator for power(xy)?
A. X^y
B. X**y
C. X^^y
D. None of the mentioned

Show Answer Answer:-B. X**y
Explanation Explanation:- In python, power operator is x**y i.e. 2**3=8.

Q 2. Which one of these is floor division?
A. /
B. //
C. %
D. None of the mentioned

Show Answer Answer:-B. //
Explanation 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.

Q 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

Show Answer Answer:-A. i,ii,iii,iv,v,vi
Explanation Explanation:- For order of precedence, just remember this PEMDAS (similar to BODMAS).

Q 4. What is the answer to this expression, 22 % 3 is?
A. 7
B. 1
C. 0
D. 5

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

Q 5. Mathematical operations can be performed on a string.
A. True
B. False

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

Q 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

Show Answer Answer:-A. Left to Right

Q 7. What is the output of this expression, 3*1**3?
A. 27
B. 9
C. 3
D. 1

Show Answer Answer:-C. 3
Explanation 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.

Q 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

Show Answer Answer:-A. Addition and Subtraction
Explanation 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.

Q 9. The expression Int(x) implies that the variable x is converted to integer.
A. True
B. False

Show Answer Answer:-A. True
Explanation Explanation:- Int(x) converts the datatype of the variable to integer and is the example of explicit data conversion.

Q 10. Which one of the following has the highest precedence in the expression?
A. Exponential
B. Addition
C. Multiplication
D. Parentheses

Show Answer Answer:-D. Parentheses
Explanation 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.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You cannot copy content of this page