Python Final 100 MCQ

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 15

Python Final MCQ Test

======================
1. Which of the following is a valid identifier:

i. 9type ii. _type iii. Same-type iv. True

2. Which of the following is a relational operator:

i. > ii. // iii. or iv. **

3. Which of the following is a logical operator:

i. + ii. /= iii. and iv. in

4. Identify the membership operator from the following:

i. in ii. not in iii. both i & ii iv. Only i

5. Which one is a arithmetic operator:

i. not ii. ** iii. both i & ii iv. Only ii

6. What will be the correct output of the statement : >>>4//3.0

i. 1 ii. 1.0 iii 1.3333 iv. None of the above

7. What will be the correct output of the statement : >>> 4+2**2*10

i. 18 ii. 80 iii. 44 iv. None of the above

8. Give the output of the following code:

>>> a,b=4,2

>>> a+b**2*10

i. 44 ii. 48 iii. 40 iv. 88

9. Give the output of the following code:

>>> a,b = 4,2.5

>>> a-b//2**2

i. 4.0 ii. 4 iii. 0 iv. None of the above

10. Give the output of the following code:


>>>a,b,c=1,2,3

>>> a//b**c+a-c*a

i. -2 ii. -2.0 iii. 2.0 iv. None of the above

11. If a=1,b=2 and c= 3 then which statement will give the output as : 2.0 from the
following:

i. >>>a%b%c+1 ii. >>>a%b%c+1.0 iii. >>>a%b%c iv. a%b%c-1

12. Which statement will give the output as : True from the following :

i. >>>not -5 ii. >>>not 5 iii. >>>not 0 iv. >>>not(5-1)

13. Give the output of the following code:

>>> 7*(8/(5//2))

i. 28 ii. 28.0 iii. 20 iv. 60

14. Give the output of the following code:

>>>import math

>>> math.ceil(1.03)+math.floor(1.03)

i. 3 ii. -3.0 iii. 3.0 iv. None of the above

15. What will be the output of the following code:

>>>import math

>>>math.fabs(-5.03)

i. 5.0 ii. 5.03 iii. -5.03 iv . None of the above

16.Single line comments in python begin with……………….. symbol.

i. # ii . “ iii . % iv . _

17. Which of the following are the fundamental building block of a python program.

i. Identifier ii. Constant iii. Punctuators iv. Tokens

18. The input() function always returns a value of ……………..type.

i. Integer ii. float iii. string iv. Complex

19. ……….. function is used to determine the data type of a variable.


i. type( ) ii. id( ) iii. print( ) iv. str( )

20. The smallest individual unit in a program is known as a……………

i. keyword ii. Reserve iii. punctuator iv. Identifier

21. Which of the following is not a decision making statement

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.

i. while ii. do-while iii. for iv. None of these

23. How many times will the following code be executed.

a=5

while a>0:

print(a)

print(“Bye”)

i. 5 times ii. Once iii. Infinite iv. None of these

24. What abandons the current iteration of the loop

i. continue ii. stop iii. infinite iv. Break

25. Find the output of the following python program

for i in range(1,15,4):

print(i, end=’,’)

i. 1,20,3 ii. 2,3,4 iii. 1,5,10,14 iv. 1,5,9,13

26. …………loop is the best when the number of iterations are not known.

i. while ii. do-while iii. for iv. None of these

27. In the nested loop ……………..loop must be terminated before the outer loop.

i. Outer ii. enclosing iii. inner iv. None of these

28. …………..statement is an empty statement in python.

i. pass ii. break iii. continue iv. if

29. How many times will the following code be executed


for i in range(1, 15 , 5):

print(i,end=’,’)

i. 3 ii. 4 iii. 1 iv. infinite

30. Symbol used to end the if statement:

i. Semicolon(;) ii. Hyphen(-) iii. Underscore( _ ) iv. colon(:)

31. Which of the following is not a python legal string operation.

i. ‘abc’+’aba’ ii. ‘abc’*3 iii. ‘abc’+3 iv. ‘abc’.lower()

32. Which of the following is not a valid string operation.

i. Slicing ii. concatenation iii. Repetition iv. floor

33. Which of the following is a mutable type.

i. string ii. tuple iii. int iv. list

34. What will be the output of the following code

str1=”I love Python”

strlen=len(str1)+5

print(strlen)

i. 18 ii. 19 iii. 13 iv. 15

35. Which method removes all the leading whitespaces from the left of the string.

i. split() ii. remove() iii. lstrip() iv rstrip()

36. It returns True if the string contains only whitespace characters, otherwise
returns

False. i) isspace() ii. strip() iii. islower() iv. isupper()

37. It converts uppercase letter to lowercase and vice versa of the given string.

i. lstrip() ii. swapcase() iii. istitle() iv. count()

38. What will be the output of the following code.

Str=’Hello World! Hello Hello’

Str.count(‘Hello’,12,25)
i. 2 ii. 3 iii. 4 iv. 5

39. What will be the output of the following code.

Str=”123456”

print(Str.isdigit())

ii. True ii. False iii. None iv. Error


40. What will be the output of the following code.

Str=”python 38”

print(Str.isalnum())

iii. True ii. False iii. None iv. Error

41. What will be the output of the following code.

Str=”pyThOn”

print(Str.swapcase())

i. PYtHoN ii. pyThon iii. Python iv. PYTHON

42. What will be the output of the following code.

Str=”Computers”

print(Str.rstrip(“rs”))

i. Computer ii. Computers iii. Compute iv. compute

43. What will be the output of the following code.

Str=”This is Meera\’ pen”

print(Str.isdigit())

i. 21 ii. 20 iii. 18 iv. 19

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’)

i. 11 time s ii. 8 times iii. 3 times iv. 5 times


45. Which of the following is the correct syntax of string slicing:

i. str_name[start:end] iii. str_name[start:step]

ii. str_name[step:end] iv. str_name[step:start]

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

A=”Virtual Reality”

print(A.replace(‘Virtual’,’Augmented’))

i. Virtual Augmented iii. Reality Augmented

ii. Augmented Virtual iv. Augmented Reality

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

print(“ComputerScience”.split(“er”,2))

i. [“Computer”,”Science”] iii. [“Comput”,”Science”]

ii. [“Comput”,”erScience”] iv. [“Comput”,”er”,”Science”]

48. Following set of commands are executed in shell, what will be the output?

>>>str="hello"

>>>str[:2]

i. he ii. lo iii. olleh iv. hello

49. ………..function will always return tuple of 3 elements.

i. index() ii. split() iii. partition() iv. strip()

50. What is the correct python code to display the last four characters of “Digital
India”

i. str[-4:] ii. str[4:] iii. str[*str] iv. str[/4:]

51. Given the list L=[11,22,33,44,55], write the output of print(L[: :-1]).

i. [1,2,3,4,5] ii. [22,33,44,55] iii. [55,44,33,22,11] iv. Error in code

52. Which of the following can add an element at any index in the list?

i. insert( ) ii. append( ) iii. extend() iv. all of these


53 Which of the following function will return a list containing all the words of the
given string?

i . split() ii. index() i i i . count() iv. list()

54. Which of the following statements are True.

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]

i. a,b,d ii. a,c,d iii. a,b,c iv. Only d

55. If a1=[20,30] a2=[20,30] a3=[‘20’,’30’] a4=[20.0,30.0] then which of the


following

statements will not return ‘False’:

a. >>> a1==a2 b. >>> a4 > a1 c. >>> a1 > a2 d. >>> a2==a2

i. b, c ii . a,b,c iii. a,c,d iv. a ,d

56. >>>a1=[10,20,30,40,50]

>>>al2=l1[1:4]

What will be the elements of list a2:

i. [10,30,50] ii. [20,30,40,50] iii. [10,20,30] iv. [20,30,40]

57. >>> l=[‘red’,’blue’]

>>> l = l + ‘yellow’

What will be the elements of list l:

i. [‘red’,’blue’,’yellow’] ii. [‘red’,’yellow’] iii. [‘red’,’blue’,’yellow’] iv. Error

58. What will be the output of the following code:

>>>l=[1,2,3,4]

>>>m=[5,6,7,8]

>>>n=m+l
>>>print(n)

i. [1,2,3,5,6,7,8] ii. [1,2,3,4,5,6,7,8] iii. [1,2,3,4][5,6,7,8] iv. Error

59. What will be the output of the following code:

>>>l=[1,2,3,4]

>>>m=l*2

>>>n=m*2

>>>print(n)

i [1,2,3,4,1,2,3,4,1,2,3,4] ii. [1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4]

iii. [1,2,3,4] [4,5,6,7] iv. [1,2,3,4]

60. Match the columns: if

>>> 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’]

i. 1-b ,2-d ,3-a ,4-c iii. 1-c,2-b,3-a,4-d

ii. 1-b,2-d,3-c,4-a iv. 1-d,2-a,3-c,4-b

61. If a list is created as

a=[1,2,3,’a’,[‘apple’,’green’],5,6,7,[‘red’,’orange’]] then what will be the output of


the

following statements:

print( a [4 ] [1] )

i. ‘apple’ iii. ‘green’

ii. ‘red’ iv. ‘orange’

62. a=[1,2,3,’a’,[‘apple’,’green’],5,6,7,[‘red’,’orange’]]
print ( a [ 8 ] [ 0 ] [ 2 ] )

i. ‘d’ iii. ‘e’

ii. ‘r’ iv. ‘o’

63. a=[1,2,3,’a’,[‘apple’,’green’],5,6,7,[‘red’,’orange’]]

print ( a [ -1] )

i. [‘apple’,’green’] iii. [‘red’,’orange’]

ii. [‘red’ ] iv. [’orange’]

64 a=[1,2,3,’a’,[‘apple’,’green’],5,6,7,[‘red’,’orange’]]

print( len ( a) )

i. 10 iii. 9

ii. 8 iv 11

65. What will be the output of the following code:

a=[1,2,3]

a.append([5,6])

print(a)

i. [1,2,3,5,6] ii. [1,2,3,[5,6]] iii. [[5,6]] iv. [1,2,3,[5,6]]

66. What will be the output of the following code:

a1=[1,2,3]

a2=[5,6]

a1.extend(a2)

print (a1)

ii. [5,6,1,2,3] ii. [1,2,3,5,6] iii. [1,3,5] iv. [1,2,3,6]

67. What will be the output of the following code:

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’))

i. 3 ii. 0 iii. 2 iv. 9

69. Which operators can be used with list?

i. in ii. not in iii. both (i)&(ii) iv. Arithmetic operator only

70. Which of the following function will return the first occurrence of the specified
element in a list.

i. sort() ii. value() iii. index() iv. sorted()

71. Which of the statement(s) is/are correct.

i. Python dictionary is an ordered collection of items.

ii. Python dictionary is a mapping of unique keys to values

iii. Dictionary is mutable.

iv. All of these.

72. ………function is used to convert a sequence data type into tuple.

i. List() ii tuple() iii TUPLE iv. tup()

73. It tup=(20,30,40,50), which of the following is incorrect

i. print(tup[3]) ii. tup[2]=55 iii. print(max(tup)) iv. print(len(tup))

74. Consider two tuples given below:

tup1=(1,2,4,3)

tup2=(1,2,3,4)

What will the following statement print(tup1<tup2)

i. True ii. False iii. Error iv. None of these

75. Which function returns the number of elements in the tuple

i. len( ) ii. max( ) iii. min( ) iv. count( )

76. Which function is used to return a value for the given key.
i. len( ) ii. get( ) iii. keys( ) iv. None of these

77. Keys of the dictionary must be

i. similar ii. unique iii. can be similar or unique iv. All of these

78. Which of the following is correct to insert a single element in a tuple .

i. T=4 ii. T=(4) iii. T(4,) iv. T=[4,]

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.

i. clear( ) ii. pop( ) iii. delete iv. rem( )

81. In dictionary the elements are accessed through

i. key ii. value iii. index iv. None of these

82. Which function will return key-value pairs of the dictionary

i. key( ) ii. values( ) iii. items( ) iv. get( )

83 Elements in a tuple can be of ………….type.

i. Dissimilar ii. Similar iii. both i & ii iv. None of these

84 To create a dictionary , key-value pairs are separated by…………….

i. (;) ii. ( , ) iii. (:) iv. ( / )

85 Which of the following statements are not correct:

a. An element in a dictionary is a combination of key-value pair

b. A tuple is a mutable data type

c. We can repeat a key in dictionary

d. clear( ) function is used to deleted the dictionary.

i. a,b,c ii. b,c,d iii. b,c,a iv. a,b,c,d

86 Which of the following statements are correct:

a. Lists can be used as keys in a dictionary


b. A tuple cannot store list as an element

c. We can use extend() function with tuple.

d. We cannot delete a dictionary once created.

i. a,b,c ii. b,c,d iii. b,c,a iv. None of these

87 Like lists, dictionaries are……………..which mean they can be changed.

i. Mutable ii. immutable iii. variable iv. None of these

88 To create an empty dictionary , we use

i. d=[ ] ii. d =( ) iii. d = {} iv. d= < >

89 To create dictionary with no items , we use

ii. Dict ii. dict( ) iii. d = [ ] iv. None of these

90 What will be the output

d1={‘rohit’:56,”Raina”:99}

print(“Raina” in d1)

i. True ii. False iii. No output iv. Error

91 Rahul has created the a tuple containing some numbers as

t = (10,20,30,40)

now he wants to do the following things help him

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()

iv. None of these

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

iv. None of these

95 Rahul has issued a statement after that the tuple t is replace with empty tuple,
identify the statement

he had issued out of the following:

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

out of the given four

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

1. tuple ( [10,20,30]) a. (10,20,30)

2. print(“Tea”,)* 3 b. 2

3. print( tuple(“Item”) ) c. ('Tea', 'Tea', 'Tea')

4. print(len(tuple([1,2]))) d. ( 'I', 't', 'e', 'm' )

i. 1-b, 2-c ,3- d , 4-a

ii. 1-a , 2-c, 3-d ,4-b

iii. 1-c , 2-d , 3-a ,4-a

iv. 1-d ,2-a 3-b , 4-c

100 Write the output of the following code:

d={‘name’:’rohan’,’dob’:’2002-03-11’,’Marks’:’98’}

d1={‘name’:‘raj’)
d1=d.copy()

print(“d1 :”d1)

i. d1 : {'name': 'rohan', 'dob': '2002-03-11', 'Marks': '98'}

ii. d1 = {'name': 'rohan', 'dob': '2002-03-11', 'Marks': '98'}

iii. {'name': 'rohan', 'dob': '2002-03-11', 'Marks': '98'}

iv. (d1 : {'name': 'rohan', 'dob': '2002-03-11', 'Marks': '98'})

You might also like