Python Multiple Choice
Python Multiple Choice
A. 1
B. Nothing is displayed
C. 0
D. An exception is thrown
Ans: C
A. 3
B. 4
C. 4 is maximum
D. None of the mentioned
Ans:C
6. What is the output of the below program?
x = 50
def func(x):
x=2
print(x,end=' ')
func(x)
print(x)
x is now 50
A. 2 50
B. 2 2
C. 50 2
D. 50 50
Ans:A
A. 2
B. 3
C. The numbers are equal
D. None of the mentioned
9. Which are the advantages of functions in python?
A. Reducing duplication of code
B. Decomposing complex problems into simpler pieces
C. Improving clarity of the code
D. All of the mentioned
Ans:D
10. What are the two main types of functions?
A. Custom function
B. Built-in function & User defined function
C. User function
D. System function
Ans:B
A. 4
B. 5
C. 1
D. An exception is thrown
Ans:B
16. If a function doesn’t have a return statement, which of the following does the function
return?
A. int
B. Null
C. None
D. -1
Ans:C
17. What will be the output of the following Python code?
def display(b, n):
while n > 0:
print(b,end="")
n=n-1
display('z',3)
A. zzz
B. zz
C. An exception is executed
D. Infinite loop
Ans:A
18. What will be the output of the following Python code?
def foo():
return total + 1
total = 0
print(foo())
A. 0
B. 1
C. error
D. none of the mentioned
Ans:B
def f1():
x=15
print(x)
x=12
f1()
A. Error
B. 12
C. 15
D. 1512
Ans:C
def f1():
x=100
print(x)
x=+1
f1()
A. Error
B. 100
C. 101
D. 99
Ans: B
21. Which of the following refers to math function/keywords?
A. sqrt
B. sin
C. pi
D. all the above
Ans:D
String
Ans: C
6. Which of the following function checks in a string that all characters are alphanumeric?
A. isalpha()
B. capitalize()
C. isalnum()
D. isdigit()
Ans: C
Ans: A
Ans: B
Ans: B
Ans: D
13. What will be the output of the following Python code snippet?
print('a@ 1,'.islower())
A. True
B. False
C. None
D. Error
Ans: A
14. What will be the output of the following Python code snippet?
print('abcefd'.replace('cd', '2'))
A. ab1ef2
B. abcefd
C. ab1efd
D. ab12ed2
Ans:B
15. What will be the output of the following Python code snippet?
print('abcdefcdghcd'.split('cd'))
16. What will be the output of the following Python code snippet?
print('ab cd-ef'.title())
A. Ab cd-ef
B. Ab Cd-ef
C. Ab Cd-Ef
D. None of the mentioned
Ans:C
a=[10,23,56,[78]]
b=a
print(b)
a[3][0]=95
a[1]=34
print(b)
A. [10,34,56,[95]]
B. [10,23,56,[78]]
C. [10,23,56,[95]]
D. [10,34,56,[78]]
Ans:A
a=[1,2,3]
b=a.append(4)
print(b)
A. [1, 2, 3, 4]
B. None
C. [1,2,3]
D. Error
Ans: B
a= [1, 2, 3, 4, 5]
for i in range(1, 5):
a[i-1] = a[i]
for i in range(0, 5):
print(a[i],end = " ")
A. 55123
B. 51234
C. 23451
D. 23455
Ans:D
5. How to find the last element of list in Python? Assume `bikes` is the name of list.
A. bikes[0]
B. bikes[-1]
C. bikes[lpos]
D. bikes[:-1]
Ans:B
Ans:B
Ans: B
10. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.count (5)?
A. 0
B. 4
C. 1
D. 2
Ans:D
General
1. What type of error the following code generates?
while i<=10:
s=s+1
i=i+1
i=0
while i=10:
i=0
s=''
s=s+i