Python Final 100 MCQ
Python Final 100 MCQ
Python Final 100 MCQ
======================
1. Which of the following is a valid identifier:
>>> a,b=4,2
>>> a+b**2*10
>>> a-b//2**2
>>> a//b**c+a-c*a
11. If a=1,b=2 and c= 3 then which statement will give the output as : 2.0 from the
following:
12. Which statement will give the output as : True from the following :
>>> 7*(8/(5//2))
>>>import math
>>> math.ceil(1.03)+math.floor(1.03)
>>>import math
>>>math.fabs(-5.03)
i. # ii . “ iii . % iv . _
17. Which of the following are the fundamental building block of a python program.
i. if..else statement ii. for statement iii. if-elif statement iv. if statement
22. …………loop is the best choice when the number of iterations are known.
a=5
while a>0:
print(a)
print(“Bye”)
for i in range(1,15,4):
print(i, end=’,’)
26. …………loop is the best when the number of iterations are not known.
27. In the nested loop ……………..loop must be terminated before the outer loop.
print(i,end=’,’)
strlen=len(str1)+5
print(strlen)
35. Which method removes all the leading whitespaces from the left of the string.
36. It returns True if the string contains only whitespace characters, otherwise
returns
37. It converts uppercase letter to lowercase and vice versa of the given string.
Str.count(‘Hello’,12,25)
i. 2 ii. 3 iii. 4 iv. 5
Str=”123456”
print(Str.isdigit())
Str=”python 38”
print(Str.isalnum())
Str=”pyThOn”
print(Str.swapcase())
Str=”Computers”
print(Str.rstrip(“rs”))
print(Str.isdigit())
44. How many times is the word ‘Python’ printed in the following statement.
s = ”I love Python”
for ch in s[3:8]:
print(‘Python’)
A=”Virtual Reality”
print(A.replace(‘Virtual’,’Augmented’))
print(“ComputerScience”.split(“er”,2))
48. Following set of commands are executed in shell, what will be the output?
>>>str="hello"
>>>str[:2]
50. What is the correct python code to display the last four characters of “Digital
India”
51. Given the list L=[11,22,33,44,55], write the output of print(L[: :-1]).
52. Which of the following can add an element at any index in the list?
a. [1,2,3,4]>[4,5,6]
b. [1,2,3,4]<[1,5,2,3]
c. [1,2,3,4]>[1,2,0,3]
d. [1,2,3,4]<[1,2,3,2]
56. >>>a1=[10,20,30,40,50]
>>>al2=l1[1:4]
>>> l = l + ‘yellow’
>>>l=[1,2,3,4]
>>>m=[5,6,7,8]
>>>n=m+l
>>>print(n)
>>>l=[1,2,3,4]
>>>m=l*2
>>>n=m*2
>>>print(n)
>>> a=list(‘computer’)
Column A Column B
1. a[1:4] a. [‘t’,’e’,’r’]
2. a[3:] b. [‘o’,’m’,’p’]
3. a[-3:] c. [‘c’,’o’,’m’,’p’,’u’,’t’]
4. a[:-2] d. [‘p’,’u’,’t’,’e’,’r’]
following statements:
print( a [4 ] [1] )
62. a=[1,2,3,’a’,[‘apple’,’green’],5,6,7,[‘red’,’orange’]]
print ( a [ 8 ] [ 0 ] [ 2 ] )
63. a=[1,2,3,’a’,[‘apple’,’green’],5,6,7,[‘red’,’orange’]]
print ( a [ -1] )
64 a=[1,2,3,’a’,[‘apple’,’green’],5,6,7,[‘red’,’orange’]]
print( len ( a) )
i. 10 iii. 9
ii. 8 iv 11
a=[1,2,3]
a.append([5,6])
print(a)
a1=[1,2,3]
a2=[5,6]
a1.extend(a2)
print (a1)
a=[1,2,3]
a.insert (2,25)
print(a)
iii. [1,2,3,25] ii. [1,25,2,3] iii. [1,2,25,3] iv. [25,1,2,3,6]
68. a=[10,20,30,40,50,60,10,20,10]
print ( a.count(‘10’))
70. Which of the following function will return the first occurrence of the specified
element in a list.
tup1=(1,2,4,3)
tup2=(1,2,3,4)
76. Which function is used to return a value for the given key.
i. len( ) ii. get( ) iii. keys( ) iv. None of these
i. similar ii. unique iii. can be similar or unique iv. All of these
79. Which of the following will delete key-value pair for key=’red’ form a dictionary
D1
i. Delete D1(“red”) ii. del. D1(“red”) iii. del D1[“red”] iv. del D1
80. Which function is used to remove all items form a particular dictionary.
d1={‘rohit’:56,”Raina”:99}
print(“Raina” in d1)
t = (10,20,30,40)
1. He want to add a new element 60 in the tuple, which statement he should use out
of the
given four.
i. t + (60)
ii. t + 60
iii. t + (60,)
iv. t + (‘60’)
92 Rahul wants to delete all the elements from the tuple, which statement he
should use
i. del t
ii. t.clear()
iii. t.remove()
93 Rahul wants to display the last element of the tuple, which statement he should
use
print(t.display() )
ii. t.pop()
iii. t[-1]
iv. t.last()
94 Rahul wants to add a new tuple t1 to the tuple t, which statement he should use
i. t+t1
ii. t.add(t1)
iii. t*t1
95 Rahul has issued a statement after that the tuple t is replace with empty tuple,
identify the statement
i. del t
ii. t= tuple()
iii.t=Tuple()
iv. delete t
96 Rahul wants to count that how many times the number 10 has come:
1. t.count(10)
ii. t[10]
iii. count.t(10)
iv. None of these
97 Rahul want to know that how many elements are there in the tuple t, which
statement he should use
i. t.count()
ii. len(t)
iii. count(t)
iv. t.sum()
98 t=(1,2,3,4)
Write the statement should be used to print the first three elements 3 times
i. print( t * 3)
ii. t*3
ii. t[:3]*3
iii. t+t
99 Match the output with the statement given in column A with Column B
2. print(“Tea”,)* 3 b. 2
d={‘name’:’rohan’,’dob’:’2002-03-11’,’Marks’:’98’}
d1={‘name’:‘raj’)
d1=d.copy()
print(“d1 :”d1)