Python Programming Quiz


Play this Python quiz that will help you to excel in C++ certification exams, placements etc. This Python programming quiz consist of 10 questions that you need to solve in 10 minutes. We’ve specially designed this quiz so that you can quickly acquaint to the pattern of questions you can be asked in placement drives, certification exams etc. This Python programming test enables you to assess your knowledge of Python programming.

Take the Free Practice Test



Python MCQs

Practice Python MCQ Questions, which will help you to understand Python programming related concepts and also helps you to prepare for placements, technical rounds, interviews, competitive exams etc.

Python Quiz

Try Free Python Quiz, to start a quiz you need to login first, after login you will get start quiz button and then by clicking on that you can start quiz. You will get 10 Minutes to answer all questions.

Python Quiz

1. What will be the output of the following Python code?

str1="learn python"
str2=""
str3=""
for x in str1:
if(x=="r" or x=="n" or x=="p"):
str2+=x
pass
if(x=="r" or x=="e" or x=="a"):
str3+=x
print(str2,end=" ")
print(str3)

rnpn ea
rnpn ear
rnp ea
rnp ear

2. What will be the output of below Python code?

class Student:
def __init__(self,name,id):
self.name=name
self.id=id
print(self.id)
std=Student("Simon",1)
std.id=2
print(std.id)

1
    1
1
    2
2
    1
2
    2

3. What will be the output of the following code?

x = "abcdef"
i = "i"
while i in x:
print(i, end=" ")

a b c d e f
abcdef
i i i i i.....
No Output

4. Parent class is the class being inherited from, also called?

derived class
Child class
Hybrid class
base class

5. What will be the output of following Python code?

set1={2,5,3}
set2={3,1}
set3={}
set3=set1&set2
print(set3)

{3}
{}
{2,5,3,1}
{2,5,1}

6. Choose the correct option.

In Python, a tuple can contain only integers as its elements.
In Python, a tuple can contain only strings as its elements.
In Python, a tuple can contain both integers and strings as its elements.
In Python, a tuple can contain either string or integer but not both at a time.

7. Which of the following is incorrect?

List is a built-in data structure in Python
List can only have elements of same data type.
List is mutable.
Index of lists can be positive as well as negative.

8. Which of the following Python code will create a set?
(i) set1=set((0,9,0))
(ii) set1=set([0,2,9])
(iii) set1={}

iii
i and ii
ii, iii
All of the above

9. Which of the following would result in an error?

def function1(var1=2, var2):
    var3=var1+var2
     return var3
    function1(3)

def function1(var1, var2):
    var3=var1+var2
    return var3
    function1(var1=2,var2=3)

def function1(var1, var2):
    var3=var1+var2
    return var3
    function1(var2=2,var1=3)

def function1(var1, var2=5):
    var3=var1+var2
    return var3
    function1(2,3)

10. What will the below Python code do?

set1={2,3}
set2={3,2}
set3={2,1}
if(set1==set2):
print("yes")
else:
print("no")
if(set1==set3):
print("yes")
else:
print("no")

Yes, No
No, No
Yes, Yes
"==" is not supported for set in Python

Results