Python MCQ Quiz - Objective Question with Answer for Python - Download Free PDF

Last updated on Feb 13, 2023

Latest Python MCQ Objective Questions

Python Question 1:

find the output of the program

a = 1  

while True:  

    if a % 9 = = 0:  

        break  

    print(a)  

    a += 1  

  1. 1 2 3 4 5 6 
  2. 1 2 3 4 5 6 7 8 
  3. 1 2 3 4 5 6 7 8 9
  4. none of these

Answer (Detailed Solution Below)

Option 2 : 1 2 3 4 5 6 7 8 

Python Question 1 Detailed Solution

Correct answer is option BImportant Points

  • program start from 1
  • check condition  if a % 9 = = 0:  
  • then run and print all the value of a till a=8
  • when a=9 then condition is false 
  • then program Break 
  • So the answer is 1 2 3 4 5 6 7 8

Python Question 2:

Write the output of the following:

>>> import pandas as pd

>>> series1=pd.Series([11,12,13])

>>> print(series1)

  1. 0  11

    1  12

    2  13

  2. 1  11

    2  12

    3  13

    dtype:int64

  3. 0  11

    1  12

    2  13

    dtype:int64

  4. 11

    12

    13

    dtype:int64

Answer (Detailed Solution Below)

Option 3 :

0  11

1  12

2  13

dtype:int64

Python Question 2 Detailed Solution

In this code we first imports the pandas library and uses it to create a pandas series object called 'series1'. A pandas series is a one-dimensional labelled array that can hold any data type.

The pd.Series() function creates a new series and takes an iterable (such as a list, tuple, or ndarray) as the argument. In this case, the iterable is the list [11,12,13].

The print() function is then used to print the contents of the series to the console.

Output of above code in python is:

0  11

1  12

2  13

dtype:int64

In the output left column shows the index of each element in the series, and the right column shows the value of each element.

Python Question 3:

What kind of  data structures are used for manipulating data in Pandas ?

  1. list and DataFrame
  2. set and dataFrame
  3. Series and DataFrame
  4. series and list

Answer (Detailed Solution Below)

Option 3 : Series and DataFrame

Python Question 3 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 Question 4:

Which of the following plots are avilable in Matplotlib?

  1. Bar Graph
  2. Scatterplot
  3. Histrogram
  4. All the above

Answer (Detailed Solution Below)

Option 4 : All the above

Python Question 4 Detailed Solution

The correct answer is option 4.

Concept:

Matplotlib:

One of the most widely-used Python libraries for data visualization is Matplotlib. It's a cross-platform library that generates 2D charts from array data. To get started, we just need to import the relevant files, prepare some data, then use the plot() method to begin charting.

Matplotlib is a Python library that uses NumPy, Python's numerical mathematics extension. There are various storylines in it, like as,

  • Line Graph
  • Bar Graph
  • Scatterplot
  • Histogram and many more.

Line Graph:

F4 Madhuri Engineering 20.05.2022 D2

Bar Graph:

new 16522953769402

F1 Rajiv Engeneering 20.05.22 G1

Scatterplot:

F4 Madhuri Engineering 20.05.2022 D3

Histogram:

F4 Madhuri Engineering 20.05.2022 D4

Hence the correct answer is All the above.

Python Question 5:

Which of the following data structure is supported by pandas library?

  1. Series
  2. Data frame
  3. Panel
  4. All of these
  5. None of above

Answer (Detailed Solution Below)

Option 4 : All of these

Python Question 5 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.

Top Python MCQ Objective Questions

Python Question 6:

What does this program print?

days = “Mon, Tue, Wed, Thu, Fri, Sat, Sun”

print(days[::5])

  1. Mon Tue Wed Thu Fri Sat Sun
  2. Fri
  3. MTWTFSS
  4. T

Answer (Detailed Solution Below)

Option 3 : MTWTFSS

Python Question 6 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 space

Python Question 7:

Which one is NOT a feature of Python language?

  1. Interpreted language
  2. Portable
  3. High level language
  4. Case Insensitive

Answer (Detailed Solution Below)

Option 4 : Case Insensitive

Python Question 7 Detailed Solution

Key Points

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 Question 8:

What will be the result of the below command in python language:

round(0.4) - round(-0.5)

  1. 0
  2. 1
  3. 2
  4. -1

Answer (Detailed Solution Below)

Option 1 : 0

Python Question 8 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) = 0

This gives, 0-(-0) = 0

NOTE: It does not depend on the negative value.The round function is used to round the value.r

Eg: round(0 to 0.5) gives as 0.

round(-0.6 to -0.9) gives as -1.

Hence the answer is 0.

Python Question 9:

What will be output of the following command in python?

print (r"\nhello")

  1. hello
  2. new line and hello
  3. \nhello
  4. Error

Answer (Detailed Solution Below)

Option 3 : \nhello

Python 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 Question 10:

What is the output of the below program in python:

print(0.2 + 0.4 == 0.6)

  1. True
  2. False
  3. Error
  4. Depends on machine

Answer (Detailed Solution Below)

Option 2 : False

Python Question 10 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 Question 11:

Which of following is keyword used in python?

  1. finally
  2. lambda
  3. for
  4. All of above

Answer (Detailed Solution Below)

Option 4 : All of above

Python Question 11 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:

False, await, else, import, pass, None, break, except, in, raise, True, class, finally, is, return, and, continue, for, lambda, try, as, def, from, nonlocal, while, assert, del, global, not, with, async, elif, if, or, yield.
The keywords listed above may change between Python versions. Some extras may be added, while others may be deleted. You may always retrieve a list of keywords in your current version by entering the following command at the prompt.
Syntax:
>>> import keyword
>>> print(keyword.kwlist)
Hence the correct answer is All of above.

Python Question 12:

What is the output of the code in Python Language:

for num in range (3):
  if num > 0:
    print (num*100)

  1. 300, 300, 300
  2. 100, 100, 100
  3. 100, 200
  4. 300, 200 

Answer (Detailed Solution Below)

Option 3 : 100, 200

Python Question 12 Detailed Solution

Key PointsPython range() Basics: In simple terms, range() allows the user to generate a series of numbers within a given range. 

for num in range (3):

if num > 0:

print (num*100)

Here num has initially 0 and it prints num × 100 gives 0 as output and next iteration num is 1 and prints 100. After num has 2 and prints 200. And finally range become closes. 

Hence the correct answer is 100,200. 
Note:- for better understanding run the above program.

Python Question 13:

What is the maximum length of a Python identifier?

  1. 33
  2. 28
  3. 14
  4. No fixed length specified

Answer (Detailed Solution Below)

Option 4 : No fixed length specified

Python Question 13 Detailed Solution

The correct answer is option 4.

Concept:

Python Identifiers are names assigned to things such as classes, functions, variables, and so on. It helps in distinguishing one entity from another.

Rules for writing identifiers:

  • An identifier can be of any length.
  • Identifiers can be a mix of lowercase (a-z) or capital (A-Z) characters, numerals (0-9), or underscore(_). Names like myClass, var_1 and print_this_to_screen, all are valid example.
  • A digit cannot be the first character of an identifier. Variable1 is an acceptable name, but 1variable is not.
  • Keywords cannot be used as identifiers.
  • In our identifier, we cannot use special characters such as !, @, #, $, percent, and so on.

Explanation:

​In python an Identifier there is no fixed length so the identifier can be of any length.

Hence the correct answer is No fixed length specified.

Python Question 14:

The given declaration statement in Python Language belongs to which data type?

>>>Student = {‘SUBJECT’ ∶ ‘Compiler’, ‘Marks’ ∶ ‘50’, ‘Grade’ ∶ ‘C’}

  1. Dictionary
  2. Sequence
  3. Sets
  4. Numbers

Answer (Detailed Solution Below)

Option 1 : Dictionary

Python Question 14 Detailed Solution

Key Points
  • Python Dictionary is used to store the data in a key-value pair format. The dictionary is the data type in Python, which can simulate the real-life data arrangement where some specific value exists for some particular key. Ex: Dict = {"Name": "Tom", "age": 22}
  • A Python set is the collection of unordered items. Each element in the set must be unique, immutable, and the sets remove the duplicate elements. Ex: Days = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}
  • In Python programming, sequences are a generic term for an ordered set which means that the order in which we input the items will be the same when we access them.
  • Python has basically three numeric data types named int, float, and complex. Since Python is a dynamically typed language we don’t have to define the data type


Hence the correct answer is Dictionary.

Python Question 15:

Which of the following data structure is supported by pandas library?

  1. Series
  2. Data frame
  3. Panel
  4. All of these

Answer (Detailed Solution Below)

Option 4 : All of these

Python Question 15 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.
Get Free Access Now