Python Quiz
Q 1 - What is the output for −
'python ' [-3]?
A - 'o'
B - 't'
C - 'h'
D - Negative index error.
Q 2 - What is output of following code −
a = (1, 2)
a[0] +=1
A - (1,1,2)
B-2
C - Type Error
D - Syntax Error
Q 3 - How can we generate random numbers in python using methods?
A - random.uniform ()
B - random.randint()
C - random.random()
D - All of the above
Q 4 - Find the output of the code?
def f(a, b = 1, c = 2):
print('a is: ',a, 'b is: ', b, 'c is: ', c)
f(2, c = 2)
f(c = 100, a = 110)
A - a is: 2 b is: 1 c is: 2
a is: 110 b is: 1 c is: 100
B - a is: 2 b is: 2 c is: 2
a is: 110 b is: 2 c is: 100
C - a is: 0 b is: 2 c is: 2
a is: 110 b is: 0 c is: 100
D - a is: 110 b is: 0 c is: 100
a is: 110 b is: 0 c is: 100
Q 5 - What is the out of the code?
def rev_func(x,length):
print(x[length-1],end='' '')
rev_func(x,length-1)
x=[11, 12, 13, 14, 15]
rev_func(x,5)
A - The program runs fine without error.
B - Program displays 15 14 13 12 11.
C - Program displays 11 12 13 14 15.
D - Program displays 15 14 13 12 11 and then raises an index out of
range exception.
Q 6 - What will be the output of the following code?
print(type(1/2))
A - <class 'float'>
B - <class 'int'>
C - NameError: ‘½’ is not defined.
D - 0.5
7. Question
A variable must be assigned a value before it can be used.
A- Yes
B- No
8. Question
Can return statement in python used to return multiple values ?
A- Yes
B- No
9. Question
In python what does // operator do ?
A. Float division
B. Integer division
C. returns remainder
D. same as a**b
10. Question
What will be the output of the following code ?
def main():
d = {}
d["jon"] = 22
d["bob"] = 27
d["tom"] = 53
d["rob"] = 87
return len(d)
print(main())
A. 3
B. 44
C. 4
D. 8
11. Question
What is the name of data type for character in python ?
A. chr
B. char
C. character
D. python do not have any data type for characters they are treated as string.
12. Question
Use of parentheses can change the order of evaluation ?
A. Yes
B. No
13. Question
In python which is the correct method to load a module ?
A. include math
B. import math
C. #include<math.h>
D. using math
14. Question
What is the need of
if __name__ == "__main__":
somemethod()
A. Create new module
B. Define generators
C. Run python module as main program
D. Create new objects
15. Question
Out of list and tuples which are mutable ?
A. tuples
B. list
C. both are mutable
16. Question
Which of the following is invalid for body of the function ?
A. break
B. continue
C. body
D. pass
17. Question
Who created python ?
A. Guido Van Rossum
B. James Gosling
C. Denis Ritchie
D. Tom Cruise
18. Question
Let a = [ 1,2,3,4,5 ] then which of the following is correct ?
A. print(a[:]) => [1,2,3,4]
B. print(a[0:]) => [2,3,4,5]
C. print(a[:100]) => [1,2,3,4,5]
D. print(a[-1:]) => [1,2]
19. Question
Is python compiled language ?
A. No
B. Yes
20. Question
what is the output of the following code?
print(type([1,2]))
A. <type 'tuple'>
B. < type 'int'>
C. < type 'set'>
D. < type 'complex'>
E. < type 'list'>