Q. What is the result of cmp(3, 1)?

  • (A) 1
  • (B) 0
  • (C) true
  • (D) false
πŸ’¬ Discuss
βœ… Correct Answer: (A) 1

Explanation: cmp(x, y) returns 1 if x > y, 0 if x == y and -1 if x < y.

Q. Which of the following is incorrect?

  • (A) float(‘inf’)
  • (B) float(‘nan’)
  • (C) float(’56’+’78’)
  • (D) float(’12+34′)
πŸ’¬ Discuss
βœ… Correct Answer: (D) float(’12+34′)

Explanation: ‘+’ cannot be converted to a float.

Q. What is the result of round(0.5) – round(-0.5)?

  • (A) 1.0
  • (B) 2.0
  • (C) 0.0
  • (D) value depends on python version
πŸ’¬ Discuss
βœ… Correct Answer: (D) value depends on python version

Explanation: the behavior of the round()

Q. The value of the expressions 4/(3*(2-1)) and 4/3*(2-1) is the same.

  • (A) true
  • (B) false
  • (C) ---
  • (D) ---
πŸ’¬ Discuss
βœ… Correct Answer: (A) true

Explanation: although the presence of parenthesis does affect the order of precedence, in the case shown above, it is not making a difference. the result of both of these expressions is 1.333333333. hence the statement is true.

Q. What will be the value of the following Python expression? 4 + 3 % 5

  • (A) 4
  • (B) 7
  • (C) 2
  • (D) 0
πŸ’¬ Discuss
βœ… Correct Answer: (B) 7

Explanation: the order of precedence is: %,+. Hence the expression above, on
simplification results in 4 + 3 = 7.
Hence the result is 7.

Q. Which of the following operators has its associativity from right to left?

  • (A) +
  • (B) //
  • (C) %
  • (D) **
πŸ’¬ Discuss
βœ… Correct Answer: (D) **

Explanation: all of the operators shown above have associativity from left to right, except exponentiation operator (**) which has its associativity from right to left.

Q. What will be the value of x in the
following Python expression?
x = int(43.55+2/2)

  • (A) 43
  • (B) 44
  • (C) 22
  • (D) 23
πŸ’¬ Discuss
βœ… Correct Answer: (B) 44

Explanation: The expression shown above is
an example of explicit conversion. It is
evaluated as int(43.55+1) = int(44.55) = 44.
Hence the result of this expression is 44.

Q. What is the value of the following expression? 2+4.00, 2**4.0

  • (A) (6.0, 16.0)
  • (B) (6.00, 16.00)
  • (C) (6, 16)
  • (D) (6.00, 16.0)
πŸ’¬ Discuss
βœ… Correct Answer: (A) (6.0, 16.0)

Explanation: the result of the expression shown above is (6.0, 16.0). this is because the result is automatically rounded off to one decimal place.

Jump to