0% found this document useful (0 votes)
293 views24 pages

Python Data Types and Structures Quiz

The document contains a series of multiple-choice questions (MCQs) and numerical answer type questions focused on Python programming concepts. It covers topics such as data types, control flow, functions, and built-in methods. The questions are designed to assess knowledge of Python syntax and functionality.

Uploaded by

Black Beast
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
293 views24 pages

Python Data Types and Structures Quiz

The document contains a series of multiple-choice questions (MCQs) and numerical answer type questions focused on Python programming concepts. It covers topics such as data types, control flow, functions, and built-in methods. The questions are designed to assess knowledge of Python syntax and functionality.

Uploaded by

Black Beast
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Multiple Choice Single Correct (MCQ-SC)

1. Who developed Python?


A) Dennis Ritchie B) Guido van Rossum C) James Gosling D) Bjarne Stroustrup

2. What is the output of print(type(5))?


A) float B) int C) str D) bool

3. Which of the following is NOT a Python keyword?


A) if B) else C) then D) for

4. Which operator is used for exponentiation in Python?


A) ^ B) ** C) % D) //

5. How do you insert comments in Python?


A) // B) /* */ C) # D) <!-- -->

6. What is the output of print("Python")?dscet


A) P B) y C) t D) h

7. Which data type is immutable?


A) list B) tuple C) set D) dictionary

8. Which of the following is the correct way to open a file named "[Link]" for
reading?
A) open("[Link]", "w") B) open("[Link]", "r") C) open("[Link]", "a") D)
open("[Link]", "rw")

9. How do you handle exceptions in Python?


A) try-except B) catch-throw C) do-catch D) try-catch

10. Which of these collection types supports key-value pairs?


A) list B) tuple C) dictionary D) set

Multiple Choice Multiple Correct (MCQ-MC)

11. Which of the following are valid Python data types?


A) list B) tuple C) map D) set E) dictionary

12. Which statements provide control flow in Python?


A) if B) while C) switch D) elif E) for

13. Which of the following are valid Python keywords?


A) def B) class C) function D) lambda E) pass
14. Which functions are built-in Python functions?
A) print() B) input() C) len() D) append()

15. Which statements can control loops?


A) break B) continue C) exit D) pass

16. The following are valid Python containers:


A) list B) tuple C) dictionary D) set E) array

17. Which of the following are numeric types in Python?


A) int B) float C) complex D) decimal

18. Select the valid methods of a list:


A) append() B) add() C) extend() D) pop()

19. Which of the following are special methods in Python classes?


A) __init__() B) __del__() C) __main__() D) __str__()

20. Which of these are Python loop structures?


A) for B) while C) do-while D) foreach

Numerical Answer Type (NAT)

21. How many elements will be in the list after: a = [1, 2]; [Link](3)?

22. What is the output of len("Hello World")?

23. How many times will this loop execute?

python

for i in range(4):

print(i)

24. What is the value of 15 % 4?

25. Number of keys in dictionary {'a':1, 'b':2, 'c':3}?

26. How many bytes does a 64-bit integer approximately take in Python memory?

27. What is the output of int("10") + 5?

28. How many characters are in the string "Python3"?

29. How many parameters are accepted by this function?

python

def add(a, b=2, *args, **kwargs):


pass

30. How many unique elements are in the list: [1, 2, 2, 3, 3]?

Here is the next batch of 50 questions:

Multiple Choice Single Correct (MCQ-SC)

31. Which of the following is the correct syntax to create a function in Python?
A) function foo(): B) def foo(): C) create foo(): D) function: foo()

32. What will be the output of: print(2 + 3 * 4)?


A) 20 B) 14 C) 24 D) 11

33. Which of the following is NOT a valid variable name?


A) _var B) var_2 C) 2var D) var2

34. What does the expression 5 // 2 evaluate to?


A) 2.5 B) 3 C) 2 D) 2.0

35. Which keyword is used to define a class in Python?


A) class B) def C) struct D) object

36. What will the following print?

python

print(type([]))

A) list B) tuple C) dict D) set

37. Which collection type does not allow duplicate elements?


A) list B) tuple C) set D) dictionary

38. What will be the output of this code snippet?

python

print("Hello".lower())

A) HELLO B) hello C) Error D) Nothing

39. Which of the following operators can be used with strings?


A) + B) * C) - D) /

40. What is the output of print(bool(''))?


A) True B) False C) Error D) None
Multiple Choice Multiple Correct (MCQ-MC)

41. Which of the following are valid Python data structures?


A) list B) tuple C) dictionary D) array E) set

42. Which of the following are loops in Python?


A) for B) while C) do-while D) switch E) else

43. Which methods can be used to add elements to a list?


A) add() B) append() C) extend() D) insert()

44. Which keywords are used in exception handling?


A) try B) except C) catch D) finally

45. Which of the following are Python variable scopes?


A) local B) global C) universal D) nonlocal

Numerical Answer Type (NAT)

46. How many characters are in the string "Python 3"?

47. What is the length of the list [1, 2, 3, 4, 5]?

48. How many times does the loop run?

python

for i in range(2, 10, 2):

pass

49. What is the output of 10 % 4 in Python?

50. How many key-value pairs exist in the dictionary {'x': 5, 'y': 10, 'z': 15}?

Multiple Choice Single Correct (MCQ-SC)

51. What will be the output of print(3 == 3)?


A) True B) False C) 1 D) 0

52. Which keyword is used to import modules in Python?


A) include B) import C) using D) require

53. What is the output of print(type( (1, 2, 3)))?


A) list B) tuple C) dict D) set

54. Which loop will always execute at least once?


A) for B) while C) do-while D) None of the above
55. What does the pass keyword do in Python?
A) Ends a loop B) Skips execution C) Does nothing D) Raises Exception

56. What will be the output of print(2 * 'Hello')?


A) Error B) HelloHello C) Hello*2 D) Hello

57. Which function is used to convert a string to an integer?


A) str() B) int() C) float() D) convert()

58. How do you create a list containing numbers from 0 to 4?


A) list(range(5)) B) [0:4] C) array(5) D) range(5)

59. What keyword is used to define an anonymous function?


A) def B) lambda C) anon D) func

60. Which of the following is a truthy value in Python?


A) 0 B) "" C) [] D) 1

Multiple Choice Multiple Correct (MCQ-MC)

61. Which of the following are valid ways to define a function in Python?
A) def fun(): B) function fun(): C) def fun(params): D) fun function():

62. Which of these are Python conditional statements?


A) if B) else C) elseif D) elif

63. Which of the following are valid string methods?


A) upper() B) lower() C) capitalize() D) toUpper()

64. Which are valid Python numeric types?


A) int B) float C) complex D) number

65. Which of these are iterable data types in Python?


A) list B) tuple C) dict D) set E) int

Numerical Answer Type (NAT)

66. How many characters are in "Data Science" (including space)?

67. What is the output of len([10, 20, 30, 40])?

68. How many iterations will this loop run?

python

i=0
while i < 7:

i += 1

69. What is the value of 7 // 2?

70. How many keys are in this dictionary: {'name':'John', 'age':30}?

Here is another batch of 50 questions:

Multiple Choice Single Correct (MCQ-SC)

71. How do you add a single element to a list?


A) add() B) append() C) insert() D) push()

72. What is the output of print(type({}))?


A) list B) dict C) set D) tuple

73. What symbol is used for floor division in Python?


A) / B) // C) % D) **

74. What is the keyword to exit a loop prematurely?


A) stop B) continue C) break D) exit

75. What is the result of bool([])?


A) True B) False C) None D) Error

76. Which function gets input from the user?


A) input() B) scan() C) userinput() D) read()

77. Which of the following is used to check equality?


A) = B) == C) != D) <>

78. What is the output of:

python

print("Hello" + "World")

A) Hello World B) HelloWorld C) Hello+World D) Error

79. What keyword starts a conditional branch?


A) if B) switch C) case D) when

80. What is the data type of the value True in Python?


A) string B) int C) bool D) None

Multiple Choice Multiple Correct (MCQ-MC)


81. Which of the following are valid tuple operations?
A) indexing B) slicing C) append() D) concatenation

82. Which of the following are Python keywords?


A) global B) lambda C) define D) try E) except

83. Which of the following are valid ways to import modules?


A) import math B) from math import sqrt C) using math D) include math

84. Which of following are valid ways to open a file?


A) open('[Link]', 'r') B) open('[Link]', 'w') C) openfile('[Link]') D) open('[Link]', 'a')

85. Which of these methods are available for lists?


A) pop() B) remove() C) delete() D) insert()

Numerical Answer Type (NAT)

86. How many characters are in "Python Programming"?

87. What is the output value of len((1, 2, 3, 4))?

88. Execute the following loop:

python

for i in range(3, 10, 3):

pass

How many iterations does this loop run?

89. What is the output of 25 % 7?

90. How many key-value pairs exist in the dictionary: {'a':1, 'b':2, 'c':3, 'd':4}?

Here is the next set of 50 questions:

Multiple Choice Single Correct (MCQ-SC)

91. What is the result of 3 + 4 * 2?


A) 14 B) 11 C) 10 D) 15

92. Which function would you use to find the largest number in a list?
A) min() B) max() C) biggest() D) largest()

93. What does the len() function return?


A) Length of a string or list B) Sum of values C) Number of function arguments D)
None
94. How would you start a block of code that will only execute if a condition is true?
A) for B) else C) if D) while

95. Which of these methods can remove an item in a list?


A) del B) pop() C) remove() D) all of the above

96. What is the type of the following: {"apple", "banana", "cherry"}?


A) list B) tuple C) set D) dictionary

97. Python comments start with


A) // B) /* C) # D) --

98. Which operator checks equality?


A) == B) = C) != D) <>

99. What will print(9 // 2) output?


A) 4 B) 4.5 C) 5 D) Error

100. How would you generate a sequence of numbers from 1 to 5?


A) range(1,5) B) range(1,6) C) range(5) D) x =

Multiple Choice Multiple Correct (MCQ-MC)

101. Which of the following are valid variable names in Python?


A) my_var B) 2var C) _var D) var2

102. Which of the following are Python booleans?


A) True B) False C) true D) FALSE

103. Which of the following are Python string methods?


A) upper() B) lower() C) capitalize() D) down()

104. Which of the following are Python built-in functions?


A) type() B) int() C) list() D) gen()

105. Which of the following are valid Python collections?


A) list B) set C) dict D) array

Numerical Answer Type (NAT)

106. How many characters are in the string "Hello World"?

107. How many elements are in the list [10, 20, 30, 40, 50]?

108. How many iterations does the following loop execute?

python
for i in range(0, 10, 2):

pass

109. What is the output of 10 % 3?

110. How many keys are in this dictionary: {'x': 1, 'y': 2, 'z': 3}?

Continuing with the next batch of 50 questions:

Multiple Choice Single Correct (MCQ-SC)

111. What is the output of print(type(3.14))?


A) int B) float C) str D) bool

112. Which keyword is used to create a new object in Python?


A) new B) create C) object D) None of these

113. How do you declare an empty dictionary in Python?


A) {} B) [] C) () D) dictionary()

114. What is the result of print(10 // 3)?


A) 3 B) 3.33 C) 4 D) Error

115. Which method is used to convert a string to lowercase?


A) lower() B) down() C) toLower() D) lowerCase()

116. How do you write a single-line comment in Python?


A) # comment B) // comment C) /* comment */ D) <!-- comment -->

117. Which keyword defines a block of code in Python?


A) def B) function C) method D) void

118. What is the output of:

python

print(type([1, 2, 3]))

A) list B) tuple C) set D) dict

119. What will be the output of print("spam" * 3)?


A) spamspamspam B) spam 3 times C) spam spam spam D) Error

120. Which of these is NOT a valid Python operator?


A) && B) and C) or D) not

Multiple Choice Multiple Correct (MCQ-MC)


121. Which of the following are valid built-in types in Python?
A) int B) float C) bool D) decimal

122. What are examples of sequence types in Python?


A) list B) tuple C) dict D) set

123. Select the valid keywords for exception handling:


A) try B) except C) finally D) catch

124. Select all valid loop control statements:


A) continue B) break C) stop D) pass

125. Select all valid Python function parameter types:


A) Positional B) Keyword C) Default D) Optional E) Variadic

Numerical Answer Type (NAT)

126. What is the length of string "Python3"?

127. How many elements are in the list [5, 4, 3, 2, 1]?

128. How many times will this loop execute?

python

for i in range(4):

pass

129. What is the output of 23 % 5?

130. How many keys does the dictionary {'a': 10, 'b': 20} have?

Continuing with the next batch of 50 questions:

Multiple Choice Single Correct (MCQ-SC)

131. Which function is used to get the ASCII value of a character in Python?
A) ascii() B) ord() C) char() D) chr()

132. What is the output of print(7 % 3)?


A) 1 B) 2 C) 0 D) 3

133. What will be the output of this code?

python

print("Hello"[::-1])
A) Hello B) olleH C) Error D) None

134. Which of the following is NOT a valid Python data type?


A) integer B) float C) byte D) real

135. How do you create an empty set in Python?


A) set() B) {} C) [] D) empty()

136. What is the output of print(2 ** 3)?


A) 6 B) 8 C) 9 D) 5

137. Which keyword starts the conditional statement in Python?


A) if B) else C) elif D) switch

138. What is the output of print(3 > 2 and 2 > 3)?


A) True B) False C) Error D) None

139. What is printed by the following code?

python

def f(x):

return x + 1

print(f(4))

A) 4 B) 5 C) None D) Error

140. How do you write multi-line comments in Python?


A) ''' Comment ''' B) /* Comment */ C) // Comment D) # Comment

Multiple Choice Multiple Correct (MCQ-MC)

141. Which of these are immutable types in Python?


A) tuple B) list C) string D) set

142. Which of the following can be used as loop control statements?


A) continue B) break C) pass D) exit

143. Which of the following are Python collection types?


A) list B) dict C) tuple D) array

144. Which of the following are Python logical operators?


A) and B) or C) not D) &&

145. Which functions are used to open and close a file?


A) open() B) close() C) read() D) write()
Numerical Answer Type (NAT)

146. How many characters are in "Data Science" including the space?

147. What is the output of len([1, 2, 3, 4])?

148. How many iterations will this loop execute?

python

for i in range(5, 10):

pass

149. What is the output of 19 % 4?

150. How many key-value pairs does this dictionary have?


{'a':1, 'b':2, 'c':3, 'd':4, 'e':5}

Here is the final batch of 50 questions to complete your set of 200:

Multiple Choice Single Correct (MCQ-SC)

151. What is the data type of the expression: 3 + 4j?


A) int B) float C) complex D) double

152. What keyword is used to create a generator in Python?


A) yield B) generate C) return D) produce

153. Which of the following is used to handle exceptions in Python?


A) try-except B) catch C) handle D) except-try

154. Which of the following converts a string to a float?


A) float() B) int() C) str() D) convert()

155. How do you remove an element from a list by value?


A) pop() B) remove() C) delete() D) discard()

156. What is the output of print("Hello World".split())?


A) 'Hello' 'World' B) ['Hello', 'World'] C) 'Hello World' D) Error

157. Which of the following is NOT a core Python data structure?


A) list B) queue C) tuple D) set

158. What is the default return value of a function that does not explicitly
return anything?
A) 0 B) None C) False D) Empty string
159. How can you check the data type of a variable x?
A) typeof(x) B) type(x) C) datatype(x) D) class(x)

160. Which of the following will create a copy of list a?


A) [Link]() B) list(a) C) a[:] D) All of these

Multiple Choice Multiple Correct (MCQ-MC)

161. Select all Python immutable data types:


A) int B) list C) tuple D) string E) set

162. Select Python keywords related to functions:


A) def B) return C) yield D) func E) lambda

163. Select valid Python Boolean values:


A) True B) False C) Yes D) No

164. Which of the following are valid loop keywords?


A) for B) while C) do D) until

165. Select all file opening modes valid in Python:


A) 'r' B) 'w' C) 'rw' D) 'a' E) 'x'

Numerical Answer Type (NAT)

166. How many characters are in "Artificial Intelligence"?

167. What is the output of len([10, 20, 30])?

168. Number of times this loop executes:

python

for i in range(1, 10, 3):

pass

169. What is the remainder when 17 is divided by 5?

170. Number of key-value pairs in {'x':1, 'y':2, 'z':3, 'a':4, 'b':5}?

171. What is the length of string "DataScience"?

172. How many elements are in the tuple (1, 2, 3, 4, 5)?

173. How many times will the while loop execute?


python

i=0

while i < 5:

i += 1

174. What is the integer division result of 25 divided by 4?

175. How many keys are there in {'first': 'John', 'last': 'Doe'}?

176. What is the output value of len("Machine Learning")?

177. How many elements are in the list [1,3,5,7,9,11]?

178. How many iterations will the loop run?

python

for i in range(5):

pass

179. What is the result of 14 % 3?

180. Number of key-value pairs in the dictionary {'a':10, 'b':20, 'c':30}?

181. Length of the string "OpenAI"?

182. How many elements are there in the set {1, 2, 2, 3, 4}?

183. How many times will this loop run?

python

for i in range(0, 7, 2):

pass

184. What is the output of 19 % 5?

185. Number of keys in dictionary {'name': 'Alice', 'age': 25, 'city': 'Delhi'}?

186. Length of "Python"?

187. How many elements are in the list [2, 4, 6, 8]?

188. Loop iterations in:


python

while i < 3:

i += 1

189. Result of 20 // 6?

190. How many keys are there in {'p':1, 'q':2}?

191. Number of characters in "Deep Learning"?

192. Number of elements in tuple (0, 2, 4, 6, 8)?

193. Loop executions:

python

for i in range(4):

pass

194. What is the output of 17 % 3?

195. Key-value pairs in dictionary {'x': 5, 'y': 10, 'z': 15}?

196. Length of string "Data"?

197. Elements in list [1, 1, 2, 3, 5]?

198. Number of loop iterations:

python

for i in range(10, 20, 3):

pass

199. What is the output of 22 % 4?

200. Keys in the dictionary {'one': 1, 'two': 2, 'three': 3}?


Answers

Here are the answers to the 200 Python questions provided:

Multiple Choice Single Correct (MCQ-SC) Answers

1. B

2. B

3. C

4. B

5. C

6. B

7. B

8. B

9. A

10. C

11. B

12. B

13. C

14. C

15. A

16. A

17. C

18. B

19. A

20. B

21. B

22. B

23. B

24. D
25. C

26. B

27. B

28. A

29. B

30. D

31. B

32. B

33. B

34. C

35. B

36. A

37. B

38. B

39. A

40. C

41. A

42. B

43. A

44. C

45. D

46. C

47. C

48. A

49. A

50. B

51. B

52. D
53. A

54. A

55. A

56. A

57. A

58. A

59. A

60. A

61. B

62. A

63. B

64. D

65. A

66. B

67. A

68. B

69. B

70. A

71. C

72. A

73. A

74. A

75. B

76. B

77. B

78. B

79. B

80. D
Multiple Choice Multiple Correct (MCQ-MC) Answers

11. A, B, D, E

12. A, B, D, E

13. A, B, D, E

14. A, B, C

15. A, B

16. A, B, C, D

17. A, B, C

18. A, C, D

19. A, B, D

20. A, B

21. A, B, C, E

22. A, B

23. B, C, D

24. A, B, D

25. A, B, D

26. A, C

27. A, B, D

28. A, B, C

29. A, B, C

30. A, B, C, D

31. A, B, D

32. A, B, D, E

33. A, B

34. A, B, D

35. A, B, D

36. A, B, C
37. A, B

38. A, B, C

39. A, B, D

40. A, B, C, E

41. A, C, D

42. A, B, C

43. A, B, C

44. A, B, C

45. A, B

46. A, C, D

47. A, B, C, E

48. A, B

49. A, B

50. A, B, D, E

Numerical Answer Type (NAT) Answers

21. 3

22. 11

23. 4

24. 3

25. 3

26. 24 (approx.)

27. 15

28. 7

29. 4

30. 3

31. 8

32. 5
33. 4

34. 2

35. 3

36. 12

37. 4

38. 7

39. 3

40. 2

41. 18

42. 4

43. 3

44. 4

45. 4

46. 11

47. 5

48. 5

49. 1

50. 3

51. 7

52. 5

53. 4

54. 3

55. 2

56. 12

57. 4

58. 5

59. 3

60. 5
61. 21

62. 3

63. 3

64. 2

65. 5

66. 11

67. 5

68. 5

69. 6

70. 2

71. 16

72. 6

73. 5

74. 2

75. 3

76. 6

77. 4

78. 4

79. 4

80. 3

81. 6

82. 4

83. 3

84. 3

85. 2

86. 13

87. 5

88. 4
89. 2

90. 3

91. 4

92. 5

93. 4

94. 2

95. 3

96. Here are detailed explanations for a selection of key questions from the set:
97.
98. Explanation for Some Multiple Choice Single
Correct Questions
99. Question 4: Python uses ** for exponentiation, not ^ which is a bitwise XOR
operator.
100. Question 7: Tuples are immutable, unlike lists, sets, and dictionaries which
are mutable types.
101. Question 8: To open a file for reading in Python, "r" mode is used in the
open() function.
102. Question 9: Python handles exceptions with try-except blocks, no catch or
similar keywords.
103. Question 33: Variable names cannot start with digits, so 2var is invalid.
104. Question 114: 10 // 3 performs floor division returning the integer quotient
3.
105. Question 119: Multiplying a string "spam" by 3 repeats it 3 times, producing
"spamspamspam".
106.
107. Explanation for Some Multiple Choice Multiple
Correct Questions
108. Question 11: Python has list, tuple, set, and dictionary as native data
structures. map is a built-in function, not a data type.
109. Question 19: __init__ initializes new objects, __del__ destroys them, and
__str__ defines string representation. __main__ is special only as a module name.
110. Question 44: Python loops can be controlled using break to exit early,
continue to skip current iteration, and pass as a placeholder; stop is not a keyword.
111. Question 125: Python functions accept positional, keyword, default, and
variadic (*args, **kwargs) parameters. Optional is not a keyword.
112.
113. Explanation for Numerical Answer Type
Questions
114. Question 23: range(4) generates 0,1,2,3 so loop iterates 4 times.
115. Question 26: Python integers use 24 bytes approximately on 64-bit systems
due to object overhead and variable length.
116. Question 28: "Python 3" has 8 characters including the space.
117. Question 37: len((1, 2, 3, 4)) returns 4, the number of elements in the
tuple.
118. Question 129: 23 % 5 gives remainder 3 (since 5*4=20 and 23-20=3).
119.
120. Please ask about any specific question or topic area for more detailed step-by-
step explanations or code demonstrations.

You might also like