05/11/2021, 13:43 Python Online Test
Python Online Test
This Python Online Test simulates a real online certification exams. You will be presented
Multiple Choice Questions (MCQs) based on Python Concepts, where you will be given four
options. You will select the best suitable answer for the question and then proceed to the next
question without wasting given time. You will get your online test score after finishing the
complete test.
Total Questions − 48 31:48:82 Max Time − 48 Min
You scored 44.68%
Total Questions: 47, Attempted: 48, Correct: 21, Time Taken: 16.19 Min
Q - Name the error that doesn’t cause program to stop/end, but the output is not the
desired result or is incorrect.
A - Syntax error
B - Runtime error
C - Logical error
D - All of the above
Answer : C
Explanation
logical error doesn’t cause the program to stop/end, but the output is not the desired result or
is incorrect.
https://www.tutorialspoint.com/python/python_online_test.htm 1/24
05/11/2021, 13:43 Python Online Test
Show Answer
Q - Find the missing code in the following program for the following output −
for i in range(5):
Missing code
Output −
01234
A - print(i)
B - print(i, \t)
C - print(i, end= '' '')
D - print(i+ '' '')
Answer : C
Show Answer
Q - What is the output of print list[1:3] if list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]?
A - [ 'abcd', 786 , 2.23, 'john', 70.2 ]
B - abcd
C - [786, 2.23]
D - None of the above.
Answer : C
Explanation
It will print elements starting from 2nd till 3rd. Output would be [786, 2.23].
Show Answer
https://www.tutorialspoint.com/python/python_online_test.htm 2/24
05/11/2021, 13:43 Python Online Test
Q - Select the code for the following output?
A - Turtle.circle(20 , ''green '')
B - Turtle.circle(''green'')
C - Turtle.dot(20 , ''green'')
D - Turtle.dot(''green'')
Answer : C
Show Answer
Q - Which of the following function merges elements in a sequence?
A - isupper()
B - join(seq)
C - len(string)
D - ljust(width[, fillchar])
Answer : B
Explanation
join(seq) − Merges (concatenates) the string representations of elements in sequence seq
into a string, with separator string.
Show Answer
Q - What is output of following code −
https://www.tutorialspoint.com/python/python_online_test.htm 3/24
05/11/2021, 13:43 Python Online Test
print('hijk'.partition('ab'))
A - ('hijk', 'cd', ' ')
B - ('hijk')
C - ('hijk', ' ', ' ')
D - Name error
Answer : C
Explanation
Since there are no separators in the given string so the output is the same string.
Show Answer
Q - Which of the following is correct about Python?
A - Python is a high-level, interpreted, interactive and object-oriented scripting language.
B - Python is designed to be highly readable.
C - It uses English keywords frequently where as other languages use punctuation, and it has
fewer syntactical constructions than other languages.
D - All of the above.
Answer : D
Explanation
All of the above options are correct.
Show Answer
Q - Which of the following function convert an integer to a character in python?
A - set(x)
https://www.tutorialspoint.com/python/python_online_test.htm 4/24
05/11/2021, 13:43 Python Online Test
B - dict(d)
C - frozenset(s)
D - chr(x)
Answer : D
Explanation
chr(x) − Converts s to a frozen set.
Show Answer
Q - What will be the output of the following code?
~~~~~19
A - 20
B - -20
C - -19
D - 19
Answer : B
Explanation
‘~number’ is equivalent to –(x+1).
Show Answer
Q - Which among them will produce {'a', 'b', 'c'}?
A - Tuple(''abc'')
B - List(''abc'')
C - Set(''abac'')
https://www.tutorialspoint.com/python/python_online_test.htm 5/24
05/11/2021, 13:43 Python Online Test
D - None of the above.
Answer : D
Explanation
Set does not allow the repetitive values in it and it separated each value present under a
string.
Show Answer
Q - Which of the following function convert an integer to octal string in python?
A - unichr(x)
B - ord(x)
C - hex(x)
D - oct(x)
Answer : D
Explanation
oct(x) − Converts an integer to an octal string.
Show Answer
Q - What is output for −
a = ['hat', 'mat', 'rat']
'rhyme'.join(a)
A - [‘hat’,’mat’,’rat’,’rhyme’]
B - ‘hatmatratrhyme’
C - [‘hat mat rat rhyme’]
D - ‘hatrhymematrhyme rat’
https://www.tutorialspoint.com/python/python_online_test.htm 6/24
05/11/2021, 13:43 Python Online Test
Answer : D
Explanation
The method join() takes list of string as input and returns string as output. It removes ‘,’ and
add the given string with join to the list.
Show Answer
Q - Which among them is incorrect for set s={100,101,102,103}
A - Len(s)
B - Sum(s)
C - Print(s[3])
D - Max(s)
Answer : C
Explanation
There is no indexing in Sets.
Show Answer
Q - What if '19' == 19 is executed in Python?
A - True
B - False
C - Error
D - Prints '19'.
Answer : B
Show Answer
https://www.tutorialspoint.com/python/python_online_test.htm 7/24
05/11/2021, 13:43 Python Online Test
Q - what is output of following code −
class Count:
def __init__(self, count=0):
self.__count=count
a=Count(2)
b=Count(2)
print(id(a)==id(b), end = '' '')
c= ''hello''
d= ''hello''
print(id(c)==id(d))
A - True False
B - False True
C - False False
D - True True
Answer : B
Explanation
The objects with same contents share the same object in the python library but this is not
true for custom-defined immutable classes.
Show Answer
Q - Which can be an Identifier among them in Python?
A - 1abc
B - $12a
C - _xy1
D - @python
Answer : C
Explanation
https://www.tutorialspoint.com/python/python_online_test.htm 8/24
05/11/2021, 13:43 Python Online Test
Because Identifiers start from letter A to Z or a to z or an underscore (_) followed by more
letters or zero or underscores and digits (0 to 9). Python does not allow @ or $ or % within
the identifier.
Show Answer
Q - What is the output for −
'Tutorials Point' [100:200]?
A - Index error.
B-''
C - 'Tutorials Point'
D - Syntax error
Answer : B
Explanation
Slicing will never give us an error even if we give it too large of an index for the string. It will
just return the widest matching slice it can.
Show Answer
Q - Which options are correct to create an empty set in Python?
A - {}
B - ()
C - []
D - set()
Answer : D
Explanation
we need to define the set by including the keyword ‘set’.
https://www.tutorialspoint.com/python/python_online_test.htm 9/24
05/11/2021, 13:43 Python Online Test
Show Answer
Q - Which of the following statement terminates the loop statement and transfers
execution to the statement immediately following the loop?
A - break
B - continue
C - pass
D - None of the above.
Answer : A
Explanation
break statement − Terminates the loop statement and transfers execution to the statement
immediately following the loop.
Show Answer
Q - What is output for − min(''hello world'')
A-e
B - a blank space character
C-w
D - None of the above.
Answer : B
Explanation
python considers a blank space character as minimum value in a string.
Show Answer
https://www.tutorialspoint.com/python/python_online_test.htm 10/24
05/11/2021, 13:43 Python Online Test
Q - Which of the following is false statement in python
A - int(144)==144
B - int('144')==144
C - int(144.0)==144
D - None of the above
Answer : D
Explanation
The built-in int() type constructor converts string and floating value to integer.
Show Answer
Q - Which of the following data types is not supported in python?
A - Numbers
B - String
C - List
D - Slice
Answer : D
Explanation
Slice is not a supported data type.
Show Answer
Q - Which module is used to sleep the python shell for the desired time? And what is
the code to do the same?
A - os, os.sleep()
https://www.tutorialspoint.com/python/python_online_test.htm 11/24
05/11/2021, 13:43 Python Online Test
B - os, os.time()
C - time, time.sleep()
D - time, time.os()
Answer : C
Show Answer
Q - Which of the following function changes case for all letters in string?
A - replace(old, new [, max])
B - strip([chars])
C - swapcase()
D - title()
Answer : C
Explanation
swapcase() − Inverts case for all letters in string.
Show Answer
Q - Which of the following function convert a String to a list in python?
A - repr(x)
B - eval(str)
C - tuple(s)
D - list(s)
Answer : D
https://www.tutorialspoint.com/python/python_online_test.htm 12/24
05/11/2021, 13:43 Python Online Test
Explanation
list(s) − Converts s to a list.
Show Answer
Q - What is output for −
b = [11,13,15,17,19,21]
ptint(b[::2])
A - [19,21]
B - [11,15]
C - [11,15,19]
D - [13,17,21]
Answer : C
Explanation
b[::2] :- it iterates over the list with ‘2’ increments
Show Answer
Q - What is the output of the following code?
string = ''Tutorials Point is best''
for i in ''.join(string.split()):
print(i, end= ''. '')
A - .T.u.t.o.r.i.a.l.s. .P.o.i.n.t. .i.s. .b.e.s.t.
B - T.u.t.o.r.i.a.l.s. .P.o.i.n.t. .i.s. .b.e.s.t
C - T.u.t.o.r.i.a.l.s. .P.o.i.n.t. .i.s. .b.e.s.t.
D - Tutorials. Point. is. best.
Answer : C
https://www.tutorialspoint.com/python/python_online_test.htm 13/24
05/11/2021, 13:43 Python Online Test
Show Answer
Q - What is the output of print list[0] if list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]?
A - [ 'abcd', 786 , 2.23, 'john', 70.2 ]
B - abcd
C - Error
D - None of the above.
Answer : B
Explanation
It will print first element of the list. Output would be abcd.
Show Answer
Q - What is the output of print str if str = 'Hello World!'?
A - Hello World!
B - Error
C - str
D - None of the above.
Answer : A
Explanation
Hello World! is the correct answer.
Show Answer
Q - Which of the following is more accurate for the following declaration?
https://www.tutorialspoint.com/python/python_online_test.htm 14/24
05/11/2021, 13:43 Python Online Test
x = Circle()
A - Now you can assign int value to x.
B - x contains a reference to a Circle object.
C - x actually contains an object of type Circle.
D - x contains an int value.
Answer : B
Explanation
x is the object created by the constructor of the class Circle().
Show Answer
Q - Select the code for the following output?
A - Canvas.showinfo(''showinfo'', ''Programming'')
B - Tkinter.showinfo(''showinfo'' , ''Programming'')
C - Tkinter.messagebox.showinfo(''Programming'')
D - Tkinter.messagebox.showinfo(''showinfo'' , ''Programming'')
Answer : D
Show Answer
https://www.tutorialspoint.com/python/python_online_test.htm 15/24
05/11/2021, 13:43 Python Online Test
Q - Using the pack manager, how you can you put the components in a container in the
same row?
A - Component.pack(side= ''LEFT'')
B - Component.pack(''Left '')
C - Component.pack(side=LEFT)
D - Component.pack(Left-side)
Answer : C
Explanation
It is the default way to do this.
Show Answer
Q - What is the output of the following code?
s = ''\t\t\t\n\nTutorialsPoint\n\n\n\t\t\t''
s.strip()
A - '\n\nTutorialsPoint\n\n\n'
B - '\t\t\tTutorialsPoint\t\t\t'
C - 'TutorialsPoint'
D - 'TutorialsPoint' , '\t\t\t\n\n \n\n\n\t\t\t'
Answer : C
Explanation
Strip method is used to remove all the newline and tab spaces code in the string.
Show Answer
Q - Suppose we are given with two sets(s1&s2) then what is the output of the code −
https://www.tutorialspoint.com/python/python_online_test.htm 16/24
05/11/2021, 13:43 Python Online Test
S1 + S2
A - Adds the elements of the both the sets.
B - Removes the repeating elements and adds both the sets.
C - It is an illegal command.
D - Output will be stored in S1.
Answer : C
Explanation
+ Operator cannot be operated on the sets.
Show Answer
Q - Which of the following function returns titlecased version of string?
A - replace(old, new [, max])
B - strip([chars])
C - swapcase()
D - title()
Answer : D
Explanation
title() − Returns "titlecased" version of string, that is, all words begin with uppercase and the
rest are lowercase.
Show Answer
Q - Which of the following environment variable for Python tells the Python interpreter
where to locate the module files imported into a program?
A - PYTHONPATH
https://www.tutorialspoint.com/python/python_online_test.htm 17/24
05/11/2021, 13:43 Python Online Test
B - PYTHONSTARTUP
C - PYTHONCASEOK
D - PYTHONHOME
Answer : A
Explanation
PYTHONPATH − It has a role similar to PATH. This variable tells the Python interpreter
where to locate the module files imported into a program. It should include the Python
source library directory and the directories containing Python source code. PYTHONPATH is
sometimes preset by the Python installer.
Show Answer
Q - What is output for −
2 * 2 **3
A - 12
B - 64
C - 16
D - 36
Answer : C
Explanation
2**3 gives 2*2*2 i.e. 8, then 2*8 gives 16, since order of precedence is ** then*. ** implies ‘‘
raise to power’’.
Show Answer
Q - Which of the following function convert a sequence of tuples to dictionary in
python?
A - set(x)
https://www.tutorialspoint.com/python/python_online_test.htm 18/24
05/11/2021, 13:43 Python Online Test
B - dict(d)
C - frozenset(s)
D - chr(x)
Answer : B
Explanation
dict(d) − Creates a dictionary. d must be a sequence of (key,value) tuples.
Show Answer
Q - Which of the following function convert a single character to its integer value in
python?
A - unichr(x)
B - ord(x)
C - hex(x)
D - oct(x)
Answer : B
Explanation
ord(x) − Converts a single character to its integer value.
Show Answer
Q - What is the output of print list[2:] if list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]?
A - [ 'abcd', 786 , 2.23, 'john', 70.2 ]
B - abcd
C - [786, 2.23]
https://www.tutorialspoint.com/python/python_online_test.htm 19/24
05/11/2021, 13:43 Python Online Test
D - [2.23, 'john', 70.2]
Answer : D
Explanation
It will print elements starting from 3rd element. Output would be [2.23, 'john', 70.2].
Show Answer
Q - Which of the following function checks in a string that all characters are
alphanumeric?
A - shuffle(lst)
B - capitalize()
C - isalnum()
D - isdigit()
Answer : C
Explanation
isalnum() − Returns true if string has at least 1 character and all characters are
alphanumeric and false otherwise.
Show Answer
Q - Syntax error in python is detected by _________at _______
A - compiler/ compile time
B - interpreter/ run time
C - compiler/ run time
D - interpreter/ compile time
https://www.tutorialspoint.com/python/python_online_test.htm 20/24
05/11/2021, 13:43 Python Online Test
Answer : B
Explanation
Syntax error in python is detected by interpreter at run time.
Show Answer
Q - What is the output of the following code?
def f(x = 100, y = 100):
return(x+y, x-y)
x, y = f(y = 200, x = 100)
print(x, y)
A - 300 -100
B - 200 0
C - 200 100
D - 0 300
Answer : A
Explanation
In variable y functions runs and gives the output of x + y and x - y i.e 300 and -100
respectively. Then assignment operator is used to assign the value of x and y.
Show Answer
Q - How can we generate random numbers in python using methods?
A - random.uniform ()
B - random.randint()
C - random.random()
D - All of the above
https://www.tutorialspoint.com/python/python_online_test.htm 21/24
05/11/2021, 13:43 Python Online Test
Answer : D
Explanation
To generate random numbers we import random module and in that module we have these
methods/functions.
uniform(x,y) returns a floating number in the range [x,y] random() returns a floating point
number in the range [0, 1].
randint(x,y) returns a random integer number in the range [x, y].
Show Answer
Q - In the following options which are python libraries which are used for data analysis
and scientific computations
A - Numpy
B - Scipy
C - Pandas
D - All the above
Answer : D
Explanation
Numpy,Scipy,pandas are few libraries in python which are used for data analysis and
scientific computations.
Show Answer
Q - Which of the following function gets the length of the string?
A - isupper()
B - join(seq)
C - len(string)
D - ljust(width[, fillchar])
https://www.tutorialspoint.com/python/python_online_test.htm 22/24
05/11/2021, 13:43 Python Online Test
Answer : C
Explanation
len(string) − Returns the length of the string.
Show Answer
Q - Which is the special symbol used in python to add comments?
A-$
B - //
C - /*.... */
D-#
Answer : D
Show Answer
Q - What is the output of 3 in [1, 2, 3]?
A - true
B - false
C - Error
D - None of the above.
Answer : A
Explanation
true
Show Answer
https://www.tutorialspoint.com/python/python_online_test.htm 23/24
05/11/2021, 13:43 Python Online Test
New Test
https://www.tutorialspoint.com/python/python_online_test.htm 24/24