Python MCQs with answers Page - 3

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 • 802.91K Points
Coach

Q. What is the type of each element in sys.argv?

  • (A) set
  • (B) list
  • (C) tuple
  • (D) string

A

Admin • 802.91K Points
Coach

Q. What is the length of sys.argv?

  • (A) number of arguments
  • (B) number of arguments + 1
  • (C) number of arguments – 1
  • (D) none of the mentioned

A

Admin • 802.91K Points
Coach

Q. What is the output of the following code?

Code:
def foo(k):
k[0] = 1
q = [0]
foo(q)
print(q)
  • (A) [0].
  • (B) [1].
  • (C) [1, 0].
  • (D) [0, 1].

A

Admin • 802.91K Points
Coach

Q. What is the output of the following code?

Code:
def foo(fname, val):
print(fname(val))
foo(max, [1, 2, 3])
foo(min, [1, 2, 3])
  • (A) 3 1
  • (B) 1 3
  • (C) error
  • (D) none of the mentioned

A

Admin • 802.91K Points
Coach

Q. What is the output of the following?

Code:
elements = [0, 1, 2]
def incr(x):
return x+1
print(list(map(elements, incr)))
  • (A) [1, 2, 3].
  • (B) [0, 1, 2].
  • (C) error
  • (D) none of the mentioned

A

Admin • 802.91K Points
Coach

Q. Program code making use of a given module is called a ______ of the module.

  • (A) Client
  • (B) Docstring
  • (C) Interface
  • (D) Modularity

A

Admin • 802.91K Points
Coach

Q. What is the output of the following piece of code?

Code:
#mod1
def change(a):
b=[x*2 for x in a]
print(b)
#mod2
def change(a):
b=[x*x for x in a]
print(b)
from mod1 import change
from mod2 import change
#main
s=[1,2,3]
change(s)
  • (A) [2,4,6].
  • (B) [1,4,9].
  • (C) [2,4,6].
  • (D) There is a name clash

A

Admin • 802.91K Points
Coach

Q. What is the output of the following program?

Code:
tday=datetime.date.today() print(tday.month())
  • (A) August
  • (B) Aug
  • (C) 08
  • (D) 8

A

Admin • 802.91K Points
Coach

Q. Which of the following formatting options can be used in order to add „n? blank spaces after a given string „S??

  • (A) print(“-ns”%S)
  • (B) print(“-ns”%S)
  • (C) print(“%ns”%S)
  • (D) print(“%-ns”%S)

A

Admin • 802.91K Points
Coach

Q. What is the output of the following program?

Code:
f = None
for i in range (5):
with open("data.txt", "w") as f:
if i > 2:
break
print(f.closed)
  • (A) True
  • (B) False
  • (C) None
  • (D) Error

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