Python MCQ Quiz - Objective Question with Answer for Python - Download Free PDF
Last updated on Jun 20, 2022
Latest Python MCQ Objective Questions
Python MCQ Question 1:
What kind of data structures are used for manipulating data in Pandas ?
Answer (Detailed Solution Below)
Python MCQ Question 1 Detailed Solution
The correct answer is option 3.
Concept:
Pandas is an open-source library designed to make it simple and natural to deal with relational or labelled data. It comes with a number of data structures and methods for manipulating numerical data and time series.
Pandas typically provide two data structures for data manipulation:
Series:
The Pandas Series is a one-dimensional label
led array that may contain any form of data (integer, string, float, python objects, etc.).DataFrame:
Pandas DataFrame is a possibly heterogeneous two-dimensional size-mutable tabular data format with labelled axes (rows and columns). A data frame is a two-dimensional data structure in which data is organised in rows and columns in a tabular format.
Hence the correct answer is Series and DataFrame.
Python MCQ Question 2:
Which of the following data structure is supported by pandas library?
Answer (Detailed Solution Below)
Python MCQ Question 2 Detailed Solution
Concept:
Pandas is an open source data analysis library suited for various kind of data. It is a high- level data manipulation tool and is built on Numpy package.
Explanation:
There are three data structure supported by pandas library:
Series: It is a one – dimensional data structure.
Data-frame: It is the two – dimensional data structure.
Panel: It is a three-dimensional data structure and includes items major_axis and minor_axis.Python MCQ Question 3:
Which of the following is not a valid set operation in python
Answer (Detailed Solution Below)
Python MCQ Question 3 Detailed Solution
The correct answer is option 4.
Concept:
Python Set Operations:
In python, Sets may be used to perform set operations such as union, intersection, difference, and symmetric difference. This is something we can achieve using operators or procedures.
Set Union:
Union of x and y is a set of all elements from both sets. Set union use | operator.
Example
x = {1, 2, 3, 4, 5}
y = {4, 5, 6, 7, 8}
print(x | y)
Output:
{1, 2, 3, 4, 5, 6, 7, 8}
Set Intersection:
The intersection of x and y is a set of elements that are common in both sets. Set intersection & operator for the set intersection.
x = {1, 2, 3, 4, 5}
y = {4, 5, 6, 7, 8}
print(x & y)
Output:
{4, 5}
Set Difference:
The difference of set B from set A (A - B) is a set of elements that are only in A but not in B. Similarly, B - A is a set of elements in B but not in A. Set difference uses - for difference operation.
A = {1, 2, 3, 4, 5}
B = {4, 5, 6, 7, 8}
print(A - B)
Output:
{1, 2, 3}
Set Symmetric Difference:
The Symmetric Difference between A and B is a set of elements in A and B but not in both (excluding the intersection). The Symmetric Difference uses ^ for the symmetric difference.
A = {1, 2, 3, 4, 5}
B = {4, 5, 6, 7, 8}
print(A ^ B)
Output:
{1, 2, 3, 6, 7, 8}
Hence the correct answer is none of the above.
Python MCQ Question 4:
Which of the following functions converts date to corresponding time in Python?
Answer (Detailed Solution Below)
Python MCQ Question 4 Detailed Solution
The correct answer is option 2.
Concept:
strptime() returns a DateTime object corresponding to the date string. Using strptime with DateTime we will format string into DateTime for I in time_data.
Example:
time_data = [ "26/05/99 12:45:0.003", "27/05/99 07:35:5.523", "28/05/99 05:15:55.523"]
format_data = "%d/%m/%y %H:%M:%S.%f"
print(datetime.strptime(i, format_data))
Output:
1999-05-26 12:45:00.003000
1999-05-27 07:35:05.523000
1999-05-28 05:15:55.523000
Hence the correct answer is strptime().
Additional Informationstrftime():
The strftime() function transforms a date, time, or DateTime object to a string representation of the specified format.
Python MCQ Question 5:
What will be the output of the following code snippet?
a = 3
b = 1
print(a, b)
a, b = b, a
print(a, b)
Answer (Detailed Solution Below)
Python MCQ Question 5 Detailed Solution
The correct answer is option 1.
Concept:
The given python snippet is,
a = 3
b = 1
print(a, b)
a, b = b, a
print(a, b)
Here "a" and "b" values are assigned.
a=3
b=1
The print function prints 3 and 1.
a, b = b, a
It is evaluated by pushing both the values to the stack and the top two values will be rotated (so that the values will be swapped) and the values are assigned back to "a" and "b".
So it swapped values become,
a=1
b=3
The print function prints 1 and 3.
Hence the correct answer is 3 1 1 3.
Top Python MCQ Objective Questions
Python MCQ Question 6:
What will be the result of below command in python language:
round(0.4) - round(-0.5)
Answer (Detailed Solution Below)
Python MCQ Question 6 Detailed Solution
In python language,
the system rounds off the number away from 0 when the number which has to be rounded off is halfway through.
This means,
round(0.4) = 0 and round(-0.5) = -1
This gives, 0-(-1) = 1
Hence the answer is 1.
Python MCQ Question 7:
What is the output of the below program in python:
print(0.2 + 0.4 == 0.6)
Answer (Detailed Solution Below)
Python MCQ Question 7 Detailed Solution
0.2, 0.4 and 0.6 can not be represented accurately in binary.
The round off errors from 0.2 and 0.4 adds up
Hence there is a difference between (0.2 + 0.4) and 0.6.
This is because you can not compare floating point value, as it cannot be considered precise.
Note:- If you run above program then we will get the output false.
Python MCQ Question 8:
Which one is NOT a feature of Python language?
Answer (Detailed Solution Below)
Python MCQ Question 8 Detailed Solution

Python is a dynamic, high-level, free open source, and interpreted programming language. It supports object-oriented programming as well as procedural-oriented programming.
Feature of Python language
- Easy to code
- Free and Open Source
- Object-Oriented Language
- GUI Programming Support
- High-Level Language
- Extensible feature
- Python is a Portable language
- Python is an Integrated language
- Interpreted Language
- Large Standard Library
- Dynamically Typed Language
- It case-sensitive programming language.
Hence the correct answer is Case insensitive.
Python MCQ Question 9:
What will be output of the following command in python?
print (r"\nhello")
Answer (Detailed Solution Below)
Python MCQ Question 9 Detailed Solution
In python language,
when 'r' or 'R' is used before the string, it converts the string into a raw string and the escape sequence like \n are not converted.
Hence the answer is \nhello.
Python MCQ Question 10:
What does this program print?
days = “Mon, Tue, Wed, Thu, Fri, Sat, Sun”
print(days[::5])Answer (Detailed Solution Below)
Python MCQ Question 10 Detailed Solution
Concept:
Slicing: It is used to slice a particular sequence. We can specify where it starts and where it will end, how many characters can be skipped.
Explanation:
Here, given code is:
days = “Mon, Tue, Wed, Thu, Fri, Sat, Sun”
print(days[::5])
Output: In this, slice starts at the first character and includes every fifth character which is : MTWTFSS
It also count space as a character.
Important Point:
“Mon, Tue” in this 4th character is spacePython MCQ Question 11:
What will be the output of the following code snippet?
a = 3
b = 1
print(a, b)
a, b = b, a
print(a, b)
Answer (Detailed Solution Below)
Python MCQ Question 11 Detailed Solution
The correct answer is option 1.
Concept:
The given python snippet is,
a = 3
b = 1
print(a, b)
a, b = b, a
print(a, b)
Here "a" and "b" values are assigned.
a=3
b=1
The print function prints 3 and 1.
a, b = b, a
It is evaluated by pushing both the values to the stack and the top two values will be rotated (so that the values will be swapped) and the values are assigned back to "a" and "b".
So it swapped values become,
a=1
b=3
The print function prints 1 and 3.
Hence the correct answer is 3 1 1 3.
Python MCQ Question 12:
The command used to start Python from the command prompt is ________.
Answer (Detailed Solution Below)
Python MCQ Question 12 Detailed Solution
Python MCQ Question 13:
Which of following is keyword used in python?
Answer (Detailed Solution Below)
Python MCQ Question 13 Detailed Solution
The correct answer is option 4.
Concept:
In Python, reserved words are referred to as keywords. A keyword cannot be used as a variable name, function name, or other identifiers.
Here's a list of all keywords in Python Programming:
Python MCQ Question 14:
Python is a/an _____
Answer (Detailed Solution Below)
Python MCQ Question 14 Detailed Solution
The correct answer is Programming language.
Key Points
- Python
- It is one of the most popular programming languages in the world.
- It is commonly used for developing websites and software, task automation, data analysis, and data visualization..
- It has become a 'go-to' in data science, allowing data analysts and other professionals to use the language to conduct complex statistical calculations, create data visualizations, build machine learning algorithms, etc.
- It can build a wide range of different data visualizations, like line and bar graphs, pie charts, histograms, and 3D plots.
- It was created by Guido van Rossum, and first released on February 20, 1991
Python MCQ Question 15:
What does the argument ‘$?’ return?
Answer (Detailed Solution Below)
Python MCQ Question 15 Detailed Solution
$? returns the exit status of the last executed function or program or command.
- echo $? - Exit status 0 returned because the last command executed successfully.
- echo $? - Non-zero exit status returned -- command failed to execute.