Q. What is the output of the following code?

Code:
print(5 // 2)
  • (A) 2.5
  • (B) 2
  • (C) 3
  • (D) Error
πŸ’¬ Discuss
βœ… Correct Answer: (B) 2
Explanation: // performs floor division, discarding the decimal part. 5 // 2 = 2.

Q. Which of these is used to define a single-line comment in Python?

  • (A) //
  • (B) /* */
  • (C) #
  • (D) <!-- -->
πŸ’¬ Discuss
βœ… Correct Answer: (C) #
Explanation: Python uses # for single-line comments.

Q. What is the output of the following code?

Code:
print(len({'a':1,'b':2,'c':3}))
  • (A) 3
  • (B) 6
  • (C) 2
  • (D) Error
πŸ’¬ Discuss
βœ… Correct Answer: (A) 3
Explanation: len() on a dictionary returns the number of keys, which is 3 here.

Q. Which function is used to find the absolute value of a number in Python?

  • (A) absolute()
  • (B) fabs()
  • (C) abs()
  • (D) mod()
πŸ’¬ Discuss
βœ… Correct Answer: (C) abs()
Explanation: The built-in abs() function returns the absolute value of a number.

Q. What is the output of the following code?

Code:
print(type(True))
  • (A) <class 'int'>
  • (B) <class 'bool'>
  • (C) <class 'str'>
  • (D) <class 'float'>
πŸ’¬ Discuss
βœ… Correct Answer: (B) <class 'bool'>
Explanation: True and False are boolean values of type bool.

Q. Which operator is used to compare both value and data type in Python?

  • (A) ==
  • (B) ===
  • (C) is
  • (D) !=
πŸ’¬ Discuss
βœ… Correct Answer: (A) ==
Explanation: Python does not have === like JavaScript. '==' checks values, while 'is' checks object identity.

Q. What is the output of the following code?

Code:
print(list('123'))
  • (A) ['1','2','3']
  • (B) [123]
  • (C) [1,2,3]
  • (D) Error
πŸ’¬ Discuss
βœ… Correct Answer: (A) ['1','2','3']
Explanation: list() converts a string into a list of characters.

Q. What is the output of the following code?

Code:
x = {1,2,3,3,2}
print(x)
  • (A) {1, 2, 3}
  • (B) {1, 2, 3, 3, 2}
  • (C) [1,2,3]
  • (D) Error
πŸ’¬ Discuss
βœ… Correct Answer: (A) {1, 2, 3}
Explanation: Sets automatically remove duplicate values, so only {1,2,3} remains.