Basic Operators
Basic Operators
a) x^y
b) x**y
c) x^^y
d) None of the mentioned
Answer: b
Explanation: In python, power operator is x**y i.e. 2**3=8.
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.
Answer: a
Explanation: For order of precedence, just remember this PEMDAS (similar to BODMAS).
Answer: b
Explanation: Modulus operator gives the remainder. So, 22%3 gives the remainder, that is, 1.
Answer: a
Explanation: None.
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.
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.
Answer: a
Explanation: int(x) converts the datatype of the variable to integer and is the example of explicit data
conversion.
10. Which one of the following has the highest precedence in the expression?
a) Exponential
b) Addition
c) Multiplication
d) Parentheses
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.