Google News
logo
Python - Quiz(MCQ)
1 .
What is the value of colors[2]?
colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']​
A)
orange
B)
yellow
C)
indigo
D)
blue

Correct Answer : Option (B) :  

yellow

2 .
What is the output of the following code?
print(3 >= 3)​
A)
True
B)
False
C)
3 >= 3
D)
None of the above

Correct Answer : Option (A) :  

True

3 .
what is the output of the following code?
print(type([1,2]))​
A)
<class 'tuple'>
B)
<class 'int'>
C)
<class 'list'>
D)
<class 'complex'>

Correct Answer : Option (C) :  

<class 'list'>

4 .
What is the output when following code is executed ?
>>> str1 = 'hello'
>>> str2 = ','
>>> str3 = 'world'
>>> str1[-1:]​
A)
olleh
B)
hello
C)
h
D)
o

Correct Answer : Option (D) :  

o

5 .
What is the output when following code is executed ?
>>>str1="helloworld"
>>>str1[::-1]
A)
dlrowolleh 
B)
hello
C)
world
D)
helloworld

Correct Answer : Option (A) :  

dlrowolleh

6 .
What will be printed:
def f(a, b):
 print(a, b)
f(b=1, *(2,))​
A)
1 2
B)
2 1
C)
This code causes TypeError
D)
None of the above

Correct Answer : Option (B) :  

2 1

7 .
What is inheritance used for?
A)
To give a class the methods and variables of an interface 
B)
To create a new object
C)
To give an interface the methods and variables of a class
D)
To give a class the variables but not the methods

Correct Answer : Option (A) :  

To give a class the methods and variables of an interface

8 .
What will be placed in a?
a = [1,2,3]
a[-3:-1] = 10,20,30,40
A)
IndexError
B)
[10, 20, 30, 40, 3]
C)
[10, 20, 30, 40, 2, 3]
D)
[10, 20, 30, 40]

Correct Answer : Option (B) :  

[10, 20, 30, 40, 3]

9 .
What does this function return?
def f(a,b):
 return a,b
f(**{'b':2,'a':1})​
A)
(1, 2)
B)
(2, 1)
C)
It causes TypeError: f() got an unexpected keyword argument
D)
All of the above

Correct Answer : Option (A) :  

(1, 2)

10 .
Which of these is not a Python datatype?
A)
int
B)
long
C)
decimal
D)
float

Correct Answer : Option (C) :  

decimal