Python Data Types MCQs (25)
Covers built-in types (int, float, bool, str, list, tuple, set, dict, range, bytes/bytearray, frozenset), mutability, hashing, conversions, slicing, and truthiness. Answers at the end
Python Training in Vizag (Softenant)1) What is the type of True + True in Python?
A. bool
B. int
C. float
D. TypeError
2) What is the output?
a = 3
b = 2.0
print(type(a + b) is float)
A. True
B. False
C. int
D. float
3) Which is immutable?
A. list
B. dict
C. tuple
D. bytearray
4) Choose the output.
s = "abc"
print(s * 2)
A. aabbcc
B. abcabc
C. Error
D. [‘abc’, ‘abc’]
5) What is printed?
x = [1, 2, 3]
y = x
x += [4]
print(y)
A. [1, 2, 3]
B. [1, 2, 3, 4]
C. Error
D. None
6) Which is hashable (can be a dict key)?
A. list
B. tuple of ints
C. dict
D. set
7) Output?
a = (1,)
b = (1)
print(type(a) is tuple, type(b) is int)
A. True False
B. True True
C. False True
D. False False
8) What is the output?
print(bool([]), bool("0"), bool(0.0))
A. False True False
B. False False False
C. True True False
D. False True True
9) Choose the result.
nums = {1, 2, 2, 3}
print(len(nums))
A. 2
B. 3
C. 4
D. Error
10) Dict view type?
d = {'a':1, 'b':2}
print(type(d.items()).__name__)
A. list
B. dict_items
C. tuple
D. view
11) Slicing output?
a = [0,1,2,3,4]
print(a[1:4:2])
A. [1,3]
B. [1,2,3]
C. [2,4]
D. [0,2,4]
12) Range materialization?
r = range(1, 6, 2)
print(list(r))
A. [1, 3, 5]
B. [1, 2, 3, 4, 5]
C. [2, 4]
D. [3, 5]
13) Bytes vs bytearray?
A. Both are mutable
B. Both are immutable
C.
bytes immutable, bytearray mutableD.
bytes mutable, bytearray immutable14) Output?
a = (1, [2, 3])
a[1].append(4)
print(a)
A. (1, [2, 3])
B. (1, [2, 3, 4])
C. TypeError
D. (1, 2, 3, 4)
15) Choose the result.
print(set("banana"))
A. {‘b’,’a’,’n’}
B. {‘banana’}
C. [‘b’,’a’,’n’]
D. Error
16) What is the output?
a = {'x':1}
b = a.copy()
a['y'] = 2
print('y' in b)
A. True
B. False
C. None
D. Error
17) Frozenset property?
A. Mutable and hashable
B. Immutable and hashable
C. Immutable and unhashable
D. Mutable and unhashable
18) Output?
x = 5
y = 5.0
print(x == y, x is y)
A. True True
B. True False
C. False True
D. False False
19) Membership test result?
d = {'a':1,'b':2}
print('a' in d, 1 in d)
A. True True
B. True False
C. False True
D. False False
20) Choose the output.
a = [1,2,3]
b = a
a = a + [4]
print(a, b)
A. [1,2,3,4] [1,2,3,4]
B. [1,2,3,4] [1,2,3]
C. [1,2,3] [1,2,3,4]
D. Error
21) Converting to int: result?
print(int(True), int(False), int(3.9))
A. 1 0 3
B. 1 0 4
C. True False 3
D. Error
22) What prints?
s = "hello"
print(s[1:-1])
A. hell
B. ell
C. ello
D. he
23) Output?
a = 0
b = 0.0
print(type(a) == type(b))
A. True
B. False
C. int
D. float
24) Choose the output.
a = (1,2)
b = (1,2)
print(a is b, a == b)
A. True True
B. False True
C. True False
D. False False
25) Which statement is TRUE?
A. Strings are mutable in Python.
B. Sets allow duplicate elements.
C. Dicts preserve insertion order (Python 3.7+).
D. A tuple can never contain a mutable object.
Answer Key
1) B
2) A
3) C
4) B
5) B
6) B
7) B
8) A
9) B
10) B
11) A
12) A
13) C
14) B
15) A
16) B
17) B
18) B
19) B
20) B
21) A
22) C
23) B
24) B
25) C