Home » Interview Questions and Answers » Python MCQ Questions and answers

Python MCQ Questions and answers

Top 80 Python MCQ questions.

  1. This software does not help in Python programming.
    1. anaconda
    2. jupyter
    3. spyder
    4. visual

Ans: visual

  1. Who developed Python?
  1. Dennis Ritchie
  2. Guido Van Rossum
  3. Bjarne Stroustrup
  4. James Arthur Gosling

Ans: Guido Van Rossum

  1. ____ is not a keyword.
    1. answer
    2. eval
    3. int
    4. print

Ans: answer

  1. In which year Python language was developed
    1. 1990
    2. 1993
    3. 1992
    4. 1991

Ans: 1991

  1. A multi-line comment in Python is written using ____ at the start and end of the block.
    1. //
    2. /*
    3. “””
    4. #

Ans: “””

  1. In which programming language Python is written
    1. Java
    2. C
    3. C++
    4. PHP

Ans: C

  1. Which of the following extension is the correct extension of the Python file?
    1. .Python
    2. .p
    3. .py
    4. None of these

Ans: .py

  1. In which year Python version 3.0 developed
    1. 2010
    2. 2011
    3. 2008
    4. 2004

Ans: 2008

  1. The results if print (“print (“An”,”Example”,sep=’–‘)) is
    1. An Example
    2. An Example —
    3. — An –Example
    4. An–Example

Ans: An–Example

  1. ____ is not a library in Python
    1. Pandas
    2. Shapiro
    3. Scipy
    4. NumPy

Ans: Shapiro

  1. The following statement is used as an abnormal loop termination
    1. Switch
    2. Break
    3. Pass
    4. Continue

Ans: switch

  1. The result of the following command is
y=3
while(y<6):
         print(y**3, end=' ')
  1. 27 64 125 216
  2. 6 9 12
  3. Endless loop
  4. 216 125 27 64

Ans: 6 9 12

  1. If sales = 3, then the result of the following command will be
if(sales>500 or sales<200):
         print("Extreme")
else:
         print("Average")
  1. Average 
  2. Extreme
  3. Error
  4. Extreme Average

Ans: Average

  1. The following command shows the result as 
for i in range(1,4):
       print(i*2, end=' ')
  1. 2 4 6 8
  2. 2 4 6
  3. 12 22 32 42
  4. 12 22 32

Ans: 2 4 6

  1. _____ terminates loop statement transfers execution to statement immediately following the loop
    1. break 
    2. while
    3. for
    4. continue

Ans: break

  1. The following is not a use of function
    1. Create once can be executed multiple times
    2. Displays the result effectively
    3. Reduces code 
    4. Easy to bug

Ans: Displays the result effectively

  1. Which is the correct syntax for defining a function sum()
    1. def sum()
    2. def sum():
    3. def sum();
    4. def function sum();

Ans: def sum():

  1. The scope of a variable can be changed using the keyword:
    1. scope_var
    2. scope
    3. global
    4. Unlimited

Ans: global

  1. It is not possible to call a function with multiple arguments
    1. True 
    2. False
    3. Both a and b
    4. Neither a and b

Ans: False

  1. A ____ function call itself from its own function body
    1. Recursive
    2. Nested
    3. Argumented
    4. Non – argumented

Ans: recursive

  1. The correct power operator in Python is:
    1. ^
    2. ^^
    3. **
    4. None of the above

Ans: **

  1. What will be the output of the code
print(22%3)
  1. 7
  2. 1
  3. 0
  4. 5

Ans: 1

  1. Which statement is correct

A. Python allows you to do mathematical operations in string.

B. Python does not support multiple inheritance.

  1. Only A
  2. Only B
  3. Both A and B
  4. None

Ans: Only B

  1. Which operators in Python have the same level of precedence?
    1. Addition 
    2. Addition and subtraction
    3. Multiplication
    4. Multiplication and division

Ans: Addition and subtraction

  1. Is Python a case sensitive programming language?
    1. Yes
    2. No
    3. It is machine dependant
    4. None of the above

Ans: Yes

  1. The maximum length of an identifier in Python is:
    1. 35 Characters
    2. 79 Characters 
    3. 10 Characters
    4. None of the above

Ans: 79 characters 

  1. Which function is not a function of a list?
    1. max
    2. mean
    3. min
    4. remove

Ans: mean()

  1. What will be the output of the code?
test_list = [100,200,300,400,300,600,300]
  1. print(test_list.count(300))
    1. 1
    2. 2
    3. 3
    4. 4

Ans: 3

  1. print(200 in test_list)
    1. true
    2. false
    3. error
    4. Not executed

Ans: true

  1. print(test_list.pop())
    1. 100
    2. 200
    3. 300
    4. 400

Ans: 300

  1. print(len(test_list))
    1. 5
    2. 6
    3. 7
    4. 8

Ans: 6

  1. print(test_list.index(200))
    1. 1
    2. 2
    3. 3
    4. 4

Ans: 1

  1. What will be the output of the code
print("x"+"yz")
  1. x+yz
  2. xyz
  3. yzx
  4. None of the above

Ans: xyz

  1. Which widget is not available in the Tkinter module
    1. Drawing
    2. Menu
    3. Radiobutton
    4. Checkbutton

Ans: Drawing

  1. What will be the output of the code
Str = "HELLO WORLD"
print(str[::-1])
  1. dlrow olleh
  2. hello
  3. world
  4. hello world

Ans: dlrow olleh

  1. The ___ function displays the details of the module and returns a sorted list of strings containing the names defined by a module.
    1. dir()
    2. details()
    3. struct()
    4. None of these

Ans: dir()

  1. The layout provided by Tkinter for arranging widgets is:
    1. Pack Layout
    2. Grid Layout
    3. Place Layout
    4. All of these

Ans: All of these

  1. The result of math.function(5) is:
    1. 510
    2. 230
    3. 120
    4. 240

Ans: 120

  1. What will be the output of the code?
for i in range(0,5):
	for j in range(0,i):
		print("*", end=" ")
	print("")

a.

* * 

* * * 

* * * * 

* * * * * 

b.

* * * * *

* * * *

* * *

* * 

*

c.

error

d.

None of the above

Ans: option a

* * 

* * * 

* * * * 

* * * * *

  1. Which function is not available in a random module?
    1. random()
    2. words()
    3. seed()
    4. randrange()

Ans: words()

  1. What will be the output of the code?
Import numpy as np
Testarray = np.array([[10,20,30],[40,50,60]])
  1. print(testarray.ndim)
    1. 1
    2. 2
    3. 3
    4. 4

Ans: 2

  1. printf(testarray.shape)
    1. (2,3)
    2. (3,2)
    3. error
    4. (3,3)

Ans: (2,3)

  1. print(testarrray.flatten())
    1. [10 20 30 40 50 60]
    2. [20 30 50 60]
    3. Error
    4. [10 30 40 60]

Ans: [10 20 30 40 50 60]

  1. print(np.diagonal(array))
    1. [10 50]
    2. [10 40]
    3. [20 50]
    4. [20 60]

Ans: [10 50]

  1. print(np.max(testarray))
    1. 30
    2. 60
    3. 40
    4. 50

Ans: 60

  1. The ___ function is used to display the starting 5 records of the dataset
    1. display()
    2. start()
    3. tail()
    4. head()

Ans: head()

  1. The ___ function displays the count, mean, standard deviation, minimum, quartiles and maximum value for each column
    1. statistics()
    2. describe()
    3. info)_
    4. stats()

Ans: describe()

  1. The function ___ is used to delete rows and columns from the dataset
    1. drop()
    2. remove()
    3. del()
    4. delete()

Ans: drop()

  1. Missing data imputation is done using the ___ function.
    1. replacena()
    2. nona()
    3. dropna()
    4. fillna()

Ans: fillna()

  1. The ___ chart is not possible to draw using only pandas library
    1. heatmap()
    2. boxplot()
    3. scatterplot()
    4. piechart()

Ans: heatmap()

  1. The ___ grip function is used to display a grid on the chart.
    1. grid()
    2. lines()
    3. grid_main()
    4. grid_chart()

Ans: grid()

  1. When we draw multiple images on one chart, we use ___ function to give title to the main image.
    1. title()
    2. maintitle()
    3. suptitle()
    4. main_title()

Ans: suptitle()

  1. The function ___ is used to set the limits of the axis.
    1. axis()
    2. lim_axis()
    3. limit_axis()
    4. axis_limit()

Ans: axis()

  1. It is possible to have more than one charts in the form of n x m array of charts using ___ function
    1. more()
    2. image()
    3. multiimage()
    4. subplot()

Ans:image()

  1. The ___ function show only the number of observations corresponding to the different values of column specified in the function.
    1. pointplot()
    2. boxplot()
    3. scatterplot()
    4. countplot()

Ans: countplot()

  1. Which of the following is correct regarding the object-oriented programming concept in Python?
    1. Classes are real world entities, while the objects are not real
    2. Objects are real world entities, while the classes are not real
    3. Both the objects and classes are real world entities
    4. All of the above

Ans: Objects are real world entities while the classes are not real.

  1. Which of the function is not built-in function in Python?
    1. print()
    2. len()
    3. add()
    4. slice()

Ans: add()

  1. If stringq1 = “WELCOME”, then the result of stringq1[::3] will be:
    1. WEO
    2. WCE
    3. LCM
    4. LCO

Ans: WCE

  1. If stringq1 = “WeLl DoNe”, then the result of print(stringq1.swapcase()) will be.
    1. wElL dOnE
    2. Well Done
    3. well done
    4. Well done

Ans: wElL dOnE

  1. If str=”Read machine learning book of same author”, then result of print(len(str)) will be
    1. 41
    2. 36
    3. 43
    4. 38

Ans: 41

  1. If str =”Effective learning”, then the result of point(s.lower().count(“e”)) will be
    1. 4
    2. 6
    3. 3
    4. 8

Ans: 4

  1. What will be the output of the code
def gfgFunction():
   "Welcome to prad tutorials"
   return 1

print(gfgFunction.__doc__[11:])
  1. prad tutorials
  2. Welcome to 
  3. Error
  4. None if these

Ans: prad tutorials 

  1. In NLTP, commonly used English words like “an”, “the”, “a” are called as
    1. General words
    2. Stop words
    3. Simple words
    4. Easy words

Ans: stop words

  1. The describe function in the scipy library does not give information related to
    1. Skewness
    2. Mean
    3. Mode 
    4. median

Ans: mode

  1. What will be the output of the code
mydict = {1: 'x', 2: 'y', 3: 'z'}
for i in mydict:
   print(i)
  1. 1 2 3
  2. x y z
  3. 1:x 2:y 3:z
  4. None of the above
  1. If data=[1,7,8,14,7,11], then the result of median(data), median_low(data) and median_high(data) will be respectively
    1. 7.5  8  7
    2. 7.5  8  8
    3. 7.5  7.5  7.5
    4. 8  7.5  7.5

Ans: 7.5  8  7

  1. If data=[1,3,5,7,3], then the result of print(stats.rankdata(data)) will be
    1. [1. 2.5 4. 5. 2.5]
    2. [1. 2 .3.4.5.]
    3. [1.3. 4. 5. 2.]
    4. [1.3. 4. 5. 3.]

Ans: [1. 2.5 4. 5. 2.5]

  1. What will be the output of the code?
print(type(type(int)))
  1. int
  2. error
  3. <class ‘type’>
  4. None of the above

Ans: <class ‘type’>

  1. If data=[“a”,”b”,”c”,”b”,”c”,”b”], then the result of print(statistics.mode(data)) will be
    1. a
    2. b
    3. c
    4. error

Ans:b

  1. ___test is not used for determining normality of data
    1. Normaltest()
    2. Shapiro
    3. Kruskal
    4. Skewness and kurtosis

Ans: Kruskal

  1. What will be the output of the code
mylist = ['prad', 'tutorials']
for i in mylist:
   mylist.append(i.upper())
print(mylist)
  1. [‘prad’, ‘tutorials’].
  2. [‘prad’, ‘tutorials’, ‘PRAD’, ‘TUTORIALS’].
  3. [None, None].
  4. None of these

Ans: None of these

  1. Which assumption is not tested before applying ANOVA
    1. Normality
    2. INdependent samples
    3. Homogeneity of variance
    4. Fisher test

Ans: Fisher test

  1. What will be the output of the code?
b = 8
c = lambda a : a * b
print (c(6))
  1. 38
  2. 26
  3. 48
  4. 10

Ans: 48

  1. The functions for comparing means are found in ___ library
    1. Numpy
    2. Scipy
    3. Pandas
    4. Matplotlib

Ans: Scipy

  1. Which is the correct syntax of the constructor?
  1. init()
  2. __init()
  3. __init__()
  4. None of these

Ans: __init__()

  1. What will be the output of the code
i = 2
while True:
   if i % 7 == 0:
       break
   print(i)
   i += 1
  1. 2 3 4 5 6 
  2. 2 3 4 5 6 7
  3. error
  4. None of these

Ans: 2 3 4 5 6

  1. Multiple pair wise-comparison between the means of groups can be done using the test.
    1. Tukey
    2. Multi
    3. Pair
    4. Multiple

Ans: Tukey

  1. The following test is a non-parametric alternative for one sample test
    1. Kolmogorov-Smirnov
    2. Mann-Whitney
    3. Shapiro-Wilk
    4. Kruskal-Wallis

Ans: Kolmogorov-Smimov

  1. What will be the output of the code?
mydata = [5,6,7]
temp = [[x for x in[mydata]] for x in range(3)]
print (temp)
  1. [[[5, 6, 7]], [[5, 6, 7]], [[5, 6, 7]]]
  2. [[5, 6, 7], [5, 6, 7], [5, 6, 7]]
  3. [[[5, 6, 7]], [[5, 6, 7]]]
  4. None of the above

Ans: [[[5, 6, 7]], [[5, 6, 7]], [[5, 6, 7]]]

  1. The following test is a non-parametric alternative for ANOVA
    1. Kolmogorov-Smirnov
    2. Mann-Whitney
    3. Shapiro-Wilk
    4. Kruskal-Wallis

Ans: Kruskal-Wallis

  1. The dataset is partitioned into two sets using the ___ function
    1. split()
    2. train_test_split()
    3. traintest_split()
    4. train_test()

Ans: train_test_split()

  1. What will be the output of the code?
dictionary = {'prad tutorials' : 'pradtutorials.com',
             'google' : 'google.com',
             'facebook' : 'facebook.com'
             }
del dictionary['google'];
for key, values in dictionary.items():
   print(key)
dictionary.clear();
for key, values in dictionary.items():
   print(key)
del dictionary;
for key, values in dictionary.items():
   print(key)
  1. Runtime error
  2. prad tutorials
    facebook
  1. Both a and b
  2. Code will not work

Ans: both a and b

  1. The logistics regression model is basically created using the following function
    1. logreg()
    2. LogisticRegression()
    3. logmodel()
    4. logregmodel()

Ans: LogisticRegression()

  1. What will be the output of the code
nameList = ['Pawan', 'Atharva', 'Omkar', 'Aniket']

print(nameList[2][-1])
  1. m
  2. a
  3. r
  4. t

Ans: r

  1. The independence of errors assumption is met if the value of Durbin-Watson is
    1. <0.05
    2. >0.05
    3. Nearly 2
    4. >10

Ans: Nearly 2

  1. The accurace_score() and confusion_matrix() are found in ___ library
    1. sklearn.metrics()
    2. sklearn.accuracy()
    3. Metrics
    4. Accuracy

Ans: sklearn.metrics()

  1. What will be the output of the code?
all([2,0,5,4])
  1. True
  2. False
  3. Error
  4. None of the above

Ans: False

Pin It on Pinterest