Python MCQs with answers Page - 9

Here, you will find a collection of MCQ questions on Python. Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

A

Admin • 831.35K Points
Coach

Q. Which of the following is the proper syntax to check if a particular element is present in a list?

  • (A) if ele in list
  • (B) if not ele not in list
  • (C) Both A and B
  • (D) None of the above

A

Admin • 831.35K Points
Coach

Q. What will be the output of the following code snippet?

Code:
def thrive(n):
 if n % 15 == 0:
   print("thrive", end = “ ”)
 elif n % 3 != 0 and n % 5 != 0:
   print("neither", end = “ ”)
 elif n % 3 == 0:
   print("three", end = “ ”)
 elif n % 5 == 0:
   print("five", end = “ ”)
thrive(35)
thrive(56)
thrive(15)
thrive(39)
  • (A) five neither thrive three
  • (B) five neither three thrive
  • (C) three three three three
  • (D) five neither five neither

A

Admin • 831.35K Points
Coach

Q. What will be the output of the following code snippet?

Code:
def check(a):
   print("Even" if a % 2 == 0 else "Odd")
   
check(12)
  • (A) Even
  • (B) Odd
  • (C) Error
  • (D) None

A

Admin • 831.35K Points
Coach

Q. What will be the output of the following code snippet?

Code:
a = [1, 2]
print(a * 3)
  • (A) Error
  • (B) [1, 2]
  • (C) [1, 2, 1, 2]
  • (D) [1, 2, 1, 2, 1, 2]

A

Admin • 831.35K Points
Coach

Q. What will be the type of the variable sorted_numbers in the below code snippet?

Code:
numbers = (4, 7, 19, 2, 89, 45, 72, 22)
sorted_numbers = sorted(numbers)
print(sorted_numbers)
  • (A) List
  • (B) Tuple
  • (C) String
  • (D) Int

A

Admin • 831.35K Points
Coach

Q. What will be the output of the following code snippet?

Code:
numbers = (4, 7, 19, 2, 89, 45, 72, 22)
sorted_numbers = sorted(numbers)
even = lambda a: a % 2 == 0
even_numbers = filter(even, sorted_numbers)
print(type(even_numbers))
  • (A) filter
  • (B) int
  • (C) list
  • (D) tuple

A

Admin • 831.35K Points
Coach

Q. What will be the output of the following code snippet?

Code:
numbers = (4, 7, 19, 2, 89, 45, 72, 22)
sorted_numbers = sorted(numbers)
odd_numbers = [x for x in sorted_numbers if x % 2 != 0]
print(odd_numbers)
  • (A) [7, 19, 45, 89]
  • (B) [2, 4, 22, 72]
  • (C) [4, 7, 19, 2, 89, 45,72, 22]
  • (D) [2, 4, 7, 19, 22, 45, 72, 89]

A

Admin • 831.35K Points
Coach

Q. What will be the output of the following code snippet?

Code:
def is_even(number):
  message =  f"{number} is an even number" if number % 2 == 0 else  f"{number} is an odd number"
 return message
print(is_even(54))
  • (A) 54 is an even number
  • (B) 54 is an odd number
  • (C) number is an even number
  • (D) number is an odd number

A

Admin • 831.35K Points
Coach

Q. What will be the output of the following code snippet?

Code:
s = {1, 2, 3, 3, 2, 4, 5, 5}
print(s)
  • (A) {1, 2, 3, 3, 2, 4, 5, 5}
  • (B) {1, 2, 3, 4, 5}
  • (C) None
  • (D) {1, 5}

A

Admin • 831.35K Points
Coach

Q. Which of the following functions converts date to corresponding time in Python?

  • (A) strptime()
  • (B) strftime()
  • (C) Both A and B
  • (D) None of the above

Add MCQ in this Category

If you want to share an MCQ question in this category, it's a great idea! It will be helpful for many other students using this website.

Share Your MCQ