Top 80 Python MCQ questions.
- This software does not help in Python programming.
- anaconda
- jupyter
- spyder
- visual
Ans: visual
- Who developed Python?
- Dennis Ritchie
- Guido Van Rossum
- Bjarne Stroustrup
- James Arthur Gosling
Ans: Guido Van Rossum
- ____ is not a keyword.
- answer
- eval
- int
Ans: answer
- In which year Python language was developed
- 1990
- 1993
- 1992
- 1991
Ans: 1991
- A multi-line comment in Python is written using ____ at the start and end of the block.
- //
- /*
- “””
- #
Ans: “””
- In which programming language Python is written
- Java
- C
- C++
- PHP
Ans: C
- Which of the following extension is the correct extension of the Python file?
- .Python
- .p
- .py
- None of these
Ans: .py
- In which year Python version 3.0 developed
- 2010
- 2011
- 2008
- 2004
Ans: 2008
- The results if print (“print (“An”,”Example”,sep=’–‘)) is
- An Example
- An Example —
- — An –Example
- An–Example
Ans: An–Example
- ____ is not a library in Python
- Pandas
- Shapiro
- Scipy
- NumPy
Ans: Shapiro
- The following statement is used as an abnormal loop termination
- Switch
- Break
- Pass
- Continue
Ans: switch
- The result of the following command is
y=3
while(y<6):
print(y**3, end=' ')
- 27 64 125 216
- 6 9 12
- Endless loop
- 216 125 27 64
Ans: 6 9 12
- If sales = 3, then the result of the following command will be
if(sales>500 or sales<200):
print("Extreme")
else:
print("Average")
- Average
- Extreme
- Error
- Extreme Average
Ans: Average
- The following command shows the result as
for i in range(1,4):
print(i*2, end=' ')
- 2 4 6 8
- 2 4 6
- 12 22 32 42
- 12 22 32
Ans: 2 4 6
- _____ terminates loop statement transfers execution to statement immediately following the loop
- break
- while
- for
- continue
Ans: break
- The following is not a use of function
- Create once can be executed multiple times
- Displays the result effectively
- Reduces code
- Easy to bug
Ans: Displays the result effectively
- Which is the correct syntax for defining a function sum()
- def sum()
- def sum():
- def sum();
- def function sum();
Ans: def sum():
- The scope of a variable can be changed using the keyword:
- scope_var
- scope
- global
- Unlimited
Ans: global
- It is not possible to call a function with multiple arguments
- True
- False
- Both a and b
- Neither a and b
Ans: False
- A ____ function call itself from its own function body
- Recursive
- Nested
- Argumented
- Non – argumented
Ans: recursive
- The correct power operator in Python is:
- ^
- ^^
- **
- None of the above
Ans: **
- What will be the output of the code
print(22%3)
- 7
- 1
- 0
- 5
Ans: 1
- Which statement is correct
A. Python allows you to do mathematical operations in string.
B. Python does not support multiple inheritance.
- Only A
- Only B
- Both A and B
- None
Ans: Only B
- Which operators in Python have the same level of precedence?
- Addition
- Addition and subtraction
- Multiplication
- Multiplication and division
Ans: Addition and subtraction
- Is Python a case sensitive programming language?
- Yes
- No
- It is machine dependant
- None of the above
Ans: Yes
- The maximum length of an identifier in Python is:
- 35 Characters
- 79 Characters
- 10 Characters
- None of the above
Ans: 79 characters
- Which function is not a function of a list?
- max
- mean
- min
- remove
Ans: mean()
- What will be the output of the code?
test_list = [100,200,300,400,300,600,300]
- print(test_list.count(300))
- 1
- 2
- 3
- 4
Ans: 3
- print(200 in test_list)
- true
- false
- error
- Not executed
Ans: true
- print(test_list.pop())
- 100
- 200
- 300
- 400
Ans: 300
- print(len(test_list))
- 5
- 6
- 7
- 8
Ans: 6
- print(test_list.index(200))
- 1
- 2
- 3
- 4
Ans: 1
- What will be the output of the code
print("x"+"yz")
- x+yz
- xyz
- yzx
- None of the above
Ans: xyz
- Which widget is not available in the Tkinter module
- Drawing
- Menu
- Radiobutton
- Checkbutton
Ans: Drawing
- What will be the output of the code
Str = "HELLO WORLD"
print(str[::-1])
- dlrow olleh
- hello
- world
- hello world
Ans: dlrow olleh
- The ___ function displays the details of the module and returns a sorted list of strings containing the names defined by a module.
- dir()
- details()
- struct()
- None of these
Ans: dir()
- The layout provided by Tkinter for arranging widgets is:
- Pack Layout
- Grid Layout
- Place Layout
- All of these
Ans: All of these
- The result of math.function(5) is:
- 510
- 230
- 120
- 240
Ans: 120
- 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
*
* *
* * *
* * * *
* * * * *
- Which function is not available in a random module?
- random()
- words()
- seed()
- randrange()
Ans: words()
- What will be the output of the code?
Import numpy as np
Testarray = np.array([[10,20,30],[40,50,60]])
- print(testarray.ndim)
- 1
- 2
- 3
- 4
Ans: 2
- printf(testarray.shape)
- (2,3)
- (3,2)
- error
- (3,3)
Ans: (2,3)
- print(testarrray.flatten())
- [10 20 30 40 50 60]
- [20 30 50 60]
- Error
- [10 30 40 60]
Ans: [10 20 30 40 50 60]
- print(np.diagonal(array))
- [10 50]
- [10 40]
- [20 50]
- [20 60]
Ans: [10 50]
- print(np.max(testarray))
- 30
- 60
- 40
- 50
Ans: 60
- The ___ function is used to display the starting 5 records of the dataset
- display()
- start()
- tail()
- head()
Ans: head()
- The ___ function displays the count, mean, standard deviation, minimum, quartiles and maximum value for each column
- statistics()
- describe()
- info)_
- stats()
Ans: describe()
- The function ___ is used to delete rows and columns from the dataset
- drop()
- remove()
- del()
- delete()
Ans: drop()
- Missing data imputation is done using the ___ function.
- replacena()
- nona()
- dropna()
- fillna()
Ans: fillna()
- The ___ chart is not possible to draw using only pandas library
- heatmap()
- boxplot()
- scatterplot()
- piechart()
Ans: heatmap()
- The ___ grip function is used to display a grid on the chart.
- grid()
- lines()
- grid_main()
- grid_chart()
Ans: grid()
- When we draw multiple images on one chart, we use ___ function to give title to the main image.
- title()
- maintitle()
- suptitle()
- main_title()
Ans: suptitle()
- The function ___ is used to set the limits of the axis.
- axis()
- lim_axis()
- limit_axis()
- axis_limit()
Ans: axis()
- It is possible to have more than one charts in the form of n x m array of charts using ___ function
- more()
- image()
- multiimage()
- subplot()
Ans:image()
- The ___ function show only the number of observations corresponding to the different values of column specified in the function.
- pointplot()
- boxplot()
- scatterplot()
- countplot()
Ans: countplot()
- Which of the following is correct regarding the object-oriented programming concept in Python?
- Classes are real world entities, while the objects are not real
- Objects are real world entities, while the classes are not real
- Both the objects and classes are real world entities
- All of the above
Ans: Objects are real world entities while the classes are not real.
- Which of the function is not built-in function in Python?
- print()
- len()
- add()
- slice()
Ans: add()
- If stringq1 = “WELCOME”, then the result of stringq1[::3] will be:
- WEO
- WCE
- LCM
- LCO
Ans: WCE
- If stringq1 = “WeLl DoNe”, then the result of print(stringq1.swapcase()) will be.
- wElL dOnE
- Well Done
- well done
- Well done
Ans: wElL dOnE
- If str=”Read machine learning book of same author”, then result of print(len(str)) will be
- 41
- 36
- 43
- 38
Ans: 41
- If str =”Effective learning”, then the result of point(s.lower().count(“e”)) will be
- 4
- 6
- 3
- 8
Ans: 4
- What will be the output of the code
def gfgFunction():
"Welcome to prad tutorials"
return 1
print(gfgFunction.__doc__[11:])
- prad tutorials
- Welcome to
- Error
- None if these
Ans: prad tutorials
- In NLTP, commonly used English words like “an”, “the”, “a” are called as
- General words
- Stop words
- Simple words
- Easy words
Ans: stop words
- The describe function in the scipy library does not give information related to
- Skewness
- Mean
- Mode
- median
Ans: mode
- What will be the output of the code
mydict = {1: 'x', 2: 'y', 3: 'z'}
for i in mydict:
print(i)
- 1 2 3
- x y z
- 1:x 2:y 3:z
- None of the above
- If data=[1,7,8,14,7,11], then the result of median(data), median_low(data) and median_high(data) will be respectively
- 7.5 8 7
- 7.5 8 8
- 7.5 7.5 7.5
- 8 7.5 7.5
Ans: 7.5 8 7
- If data=[1,3,5,7,3], then the result of print(stats.rankdata(data)) will be
- [1. 2.5 4. 5. 2.5]
- [1. 2 .3.4.5.]
- [1.3. 4. 5. 2.]
- [1.3. 4. 5. 3.]
Ans: [1. 2.5 4. 5. 2.5]
- What will be the output of the code?
print(type(type(int)))
- int
- error
- <class ‘type’>
- None of the above
Ans: <class ‘type’>
- If data=[“a”,”b”,”c”,”b”,”c”,”b”], then the result of print(statistics.mode(data)) will be
- a
- b
- c
- error
Ans:b
- ___test is not used for determining normality of data
- Normaltest()
- Shapiro
- Kruskal
- Skewness and kurtosis
Ans: Kruskal
- What will be the output of the code
mylist = ['prad', 'tutorials']
for i in mylist:
mylist.append(i.upper())
print(mylist)
- [‘prad’, ‘tutorials’].
- [‘prad’, ‘tutorials’, ‘PRAD’, ‘TUTORIALS’].
- [None, None].
- None of these
Ans: None of these
- Which assumption is not tested before applying ANOVA
- Normality
- INdependent samples
- Homogeneity of variance
- Fisher test
Ans: Fisher test
- What will be the output of the code?
b = 8
c = lambda a : a * b
print (c(6))
- 38
- 26
- 48
- 10
Ans: 48
- The functions for comparing means are found in ___ library
- Numpy
- Scipy
- Pandas
- Matplotlib
Ans: Scipy
- Which is the correct syntax of the constructor?
- init()
- __init()
- __init__()
- None of these
Ans: __init__()
- What will be the output of the code
i = 2
while True:
if i % 7 == 0:
break
print(i)
i += 1
- 2 3 4 5 6
- 2 3 4 5 6 7
- error
- None of these
Ans: 2 3 4 5 6
- Multiple pair wise-comparison between the means of groups can be done using the test.
- Tukey
- Multi
- Pair
- Multiple
Ans: Tukey
- The following test is a non-parametric alternative for one sample test
- Kolmogorov-Smirnov
- Mann-Whitney
- Shapiro-Wilk
- Kruskal-Wallis
Ans: Kolmogorov-Smimov
- 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)
- [[[5, 6, 7]], [[5, 6, 7]], [[5, 6, 7]]]
- [[5, 6, 7], [5, 6, 7], [5, 6, 7]]
- [[[5, 6, 7]], [[5, 6, 7]]]
- None of the above
Ans: [[[5, 6, 7]], [[5, 6, 7]], [[5, 6, 7]]]
- The following test is a non-parametric alternative for ANOVA
- Kolmogorov-Smirnov
- Mann-Whitney
- Shapiro-Wilk
- Kruskal-Wallis
Ans: Kruskal-Wallis
- The dataset is partitioned into two sets using the ___ function
- split()
- train_test_split()
- traintest_split()
- train_test()
Ans: train_test_split()
- 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)
- Runtime error
- prad tutorials
facebook
- Both a and b
- Code will not work
Ans: both a and b
- The logistics regression model is basically created using the following function
- logreg()
- LogisticRegression()
- logmodel()
- logregmodel()
Ans: LogisticRegression()
- What will be the output of the code
nameList = ['Pawan', 'Atharva', 'Omkar', 'Aniket']
print(nameList[2][-1])
- m
- a
- r
- t
Ans: r
- The independence of errors assumption is met if the value of Durbin-Watson is
- <0.05
- >0.05
- Nearly 2
- >10
Ans: Nearly 2
- The accurace_score() and confusion_matrix() are found in ___ library
- sklearn.metrics()
- sklearn.accuracy()
- Metrics
- Accuracy
Ans: sklearn.metrics()
- What will be the output of the code?
all([2,0,5,4])
- True
- False
- Error
- None of the above
Ans: False