Basic Operators
This section on Python aptitude questions and answers focuses on “Basic Operators”.
1. Which is the correct operator for power(x^y)?
a) X^y
b) X**y
c) X^^y
d) None of the mentioned
View Answer
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.
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
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.
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) Division
iv) Multiplication
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
i) Parentheses
ii) Exponential
iii) Division
iv) Multiplication
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 PEDMAS.
Explanation: For order of precedence, just remember this PEDMAS.
4. What is answer of this expression, 22 % 3 is?
a) 7
b) 1
c) 0
d) 5
View Answer
a) 7
b) 1
c) 0
d) 5
View Answer
Answer: b
Explanation: Modulus operator gives remainder. So, 22%3 gives 1 remainder.
Explanation: Modulus operator gives remainder. So, 22%3 gives 1 remainder.
5. You can perform mathematical operation on String?
a) True
b) False
View Answer
a) True
b) False
View Answer
Answer: b
Explanation: You can’t perform mathematical operation on string even if string looks like integers.
Explanation: You can’t perform mathematical operation on string even if string looks like integers.
6. Operators with the same precedence are evaluated in which manner?
a) Left to Right
b) Right to Left
View Answer
a) Left to Right
b) Right to Left
View Answer
Answer: a
Explanation: None.
Explanation: None.
7. What is the output of this expression, 3*1**3?
a) 27
b) 9
c) 3
d) 1
View Answer
a) 27
b) 9
c) 3
d) 1
View Answer
Answer: c
Explanation: First this expression will solve 1**3 because exponential have higher precedence than multiplication, so 1**3 = 1 and 3*1 = 3. Final answer is 3.
Explanation: First this expression will solve 1**3 because exponential have higher precedence than multiplication, so 1**3 = 1 and 3*1 = 3. Final answer is 3.
8. Which one of the following have the same precedence?
a) Addition and Subtraction
b) Multiplication and Division
c) a and b
d) None of the mentioned
View Answer
a) Addition and Subtraction
b) Multiplication and Division
c) a and b
d) None of the mentioned
View Answer
Answer: c
Explanation: None.
Explanation: None.
9. Int(x) means variable x is converted to integer.
a) True
b) False
View Answer
a) True
b) False
View Answer
Answer: a
Explanation: None.
Explanation: None.
10. Which one of the following have the highest precedence in the expression?
a) Exponential
b) Addition
c) Multiplication
d) Parentheses
View Answer
a) Exponential
b) Addition
c) Multiplication
d) Parentheses
View Answer
Answer: d
Explanation: None.
Explanation: None.
No comments:
Post a Comment