Python MCQ Quiz - Objective Question with Answer for Python - Download Free PDF
Last updated on Oct 25, 2023
Latest Python MCQ Objective Questions
Python Question 1:
What are Python files containing Python definitions and statements called?
Answer (Detailed Solution Below)
Python Question 1 Detailed Solution
Python files containing Python definitions and statements are called modules. So the answer is (3).
Key Points
- A module is a file that contains Python code, such as functions, classes, and variables. Modules can be imported into other Python files, which allows you to reuse code and organize your code into smaller, more manageable files.
- Modules are typically named with a .py extension. For example, a module named my_module.py would contain Python code that can be imported into other Python files using the following statement:
- import my_module
- Once you have imported a module, you can access the code in that module using the module's name. For example, if you have a function called greet() in the my_module.py module, you can call that function from another Python file using the following statement:
- my_module.greet()
- Modules are a powerful feature of Python that allow you to write more organized and reusable code.
Additional Information
- Flowcharts are visual representations of algorithms.
- Algorithms are step-by-step instructions for solving a problem.
- Sequences are ordered lists of elements.
Python Question 2:
find the output of the program
a = 1
while True:
if a % 9 = = 0:
break
print(a)
a += 1
Answer (Detailed Solution Below)
Python Question 2 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 3:
What is the output of following code:
print (type(type(int)))
Answer (Detailed Solution Below)
Python Question 3 Detailed Solution
Concept:
Type function type() : It either returns the type of the object or returns a new type object based on the argument passed to it.
Explanation:
If we pass single object to type(), then it returns its type.
Here code is given as:
Print type(type(int))
It returns the class of the argument to which object belongs. So, it return type
Python Question 4:
What is output of the code in Python Language:
>>> str1 = ‘All the Best’
>>> str1[-3]
Answer (Detailed Solution Below)
Python Question 4 Detailed Solution
str1 = ‘All the Best’
Here str1 is an array of continuous elements,
str1[0]=A=str1[-0]
str1[1]=l=str1[-11]
str1[2]=l=str1[-10]
str1[3]=' '=str1[-9]
str1[4]=t=str1[-8]
str1[5]=h=str1[-7]
str1[6]=e=str1[-6]
str1[7]=' '=str1[-5]
str1[8]=B=str1[-4]
str1[9]=e=str1[-3]
str1[10]=s=str1[-2]
str1[11]=t=str1[-1]
Hence the correct answer is 'e'.
Python Question 5:
What will be the output of the following command in python?
a = "python"
while i in a:
a= a[:-1]
print(i, end = " ")
Answer (Detailed Solution Below)
Python Question 5 Detailed Solution
In python language,
:-1 is called list indexing or slicing, and it returns the whole message as it is but without the last element.
You can always change the number to -2 or -3 according to the requirement.
Hence the answer will be p p p p p p.
In every loop one letter will be eliminated from the string and p will be printed with " " string in the end.
Note:- For better understanding try to run the above program.
Top Python MCQ Objective Questions
Python Question 6:
Which one is NOT a feature of Python language?
Answer (Detailed Solution Below)
Python Question 6 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 Question 7:
What does this program print?
days = “Mon, Tue, Wed, Thu, Fri, Sat, Sun”
print(days[::5])Answer (Detailed Solution Below)
Python Question 7 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 Question 8:
The command used to start Python from the command prompt is ________.
Answer (Detailed Solution Below)
Python Question 8 Detailed Solution
To execute python from the command prompt, 'python' and 'py' commands is entered.
The Correct Answer is Both py and python.
Python Question 9:
What is the output of the below program in python:
print(0.2 + 0.4 == 0.6)
Answer (Detailed Solution Below)
Python Question 9 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 10:
What will be output of the following command in python?
print (r"\nhello")
Answer (Detailed Solution Below)
Python Question 10 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 11:
What will be the result of the below command in python language:
round(0.4) - round(-0.5)
Answer (Detailed Solution Below)
Python Question 11 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 12:
What is the output of the code in Python Language:
for num in range (3):
if num > 0:
print (num*100)
Answer (Detailed Solution Below)
Python Question 12 Detailed Solution
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:
Which of following is keyword used in python?
Answer (Detailed Solution Below)
Python 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 Question 14:
What will be the output of the following command in python?
a = "python"
while i in a:
a= a[:-1]
print(i, end = " ")
Answer (Detailed Solution Below)
Python Question 14 Detailed Solution
In python language,
:-1 is called list indexing or slicing, and it returns the whole message as it is but without the last element.
You can always change the number to -2 or -3 according to the requirement.
Hence the answer will be p p p p p p.
In every loop one letter will be eliminated from the string and p will be printed with " " string in the end.
Note:- For better understanding try to run the above program.
Python Question 15:
What is the maximum length of a Python identifier?
Answer (Detailed Solution Below)
Python Question 15 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.