Python Variables & Data Types MCQs

1 min read

Variables in Python act as dynamic references reserved in memory to store objects, operating without explicit data type declarations due to Python’s dynamically typed nature. Built-in primitive and sequence data types including integers (int), floating-point numbers (float), strings (str), booleans (bool), lists (list), tuples (tuple), dictionaries (dict), and sets (set) form the building blocks of data manipulation. A key concept in Python memory management is the distinction between mutable types (whose state can change in place) and immutable types (whose state cannot be altered after creation). This 25-question quiz covers variable initialization, naming conventions, type casting, object identity, mutability, and standard data structures.

1. Which of the following is a valid variable name in Python?

a) 2my_var
b) my-var
c) _my_var
d) my var
Correct Answer: c) _my_var
Explanation:
Python variable names can contain letters, numbers, and underscores, but they cannot start with a digit, nor can they contain hyphens or spaces.

2. Which built-in function returns the data type of an object in Python?

a) typeof()
b) type()
c) datatype()
d) get_type()
Correct Answer: b) type()
Explanation:
The built-in type() function returns the exact data type of the specified variable or object.

3. Which of the following data types in Python is immutable?

a) List
b) Dictionary
c) Set
d) Tuple
Correct Answer: d) Tuple
Explanation:
Tuples are immutable sequence types in Python; once initialized, their elements cannot be changed, added, or removed.

4. What is the data type of x after executing x = 5 / 2 in Python 3?

a) int
b) float
c) double
d) decimal
Correct Answer: b) float
Explanation:
In Python 3, the standard division operator (/) always returns a float object (e.g., 2.5), even when both operands are integers.

5. What is the output of type(1_000_000) in Python?

a)
b)
c)
d) SyntaxError
Correct Answer: a)
Explanation:
Python allows underscores in numeric literals as visual grouping separators. The value 1_000_000 is parsed purely as an integer 1000000.

6. Which of the following is NOT a core built-in numeric type in Python?

a) int
b) float
c) complex
d) double
Correct Answer: d) double
Explanation:
Python does not have a separate 'double' primitive type. Real numbers with double-precision floating points are simply represented as 'float'.

7. What will be the output of bool(0) and bool(1)?

a) True, False
b) False, True
c) False, False
d) True, True
Correct Answer: b) False, True
Explanation:
The integer 0 evaluates to False in boolean context, whereas any non-zero numeric value evaluates to True.

8. Which keyword is used to declare a variable in Python?

a) var
b) let
c) int
d) None of the above
Correct Answer: d) None of the above
Explanation:
Python uses dynamic typing and implicit variable declaration. Variables are created automatically when assigned a value using the '=' operator.

9. What will print(type({1, 2, 3})) output?

a)
b)
c)
d)
Correct Answer: b)
Explanation:
Curly braces containing comma-separated values without colon key-value pairs define a set object.

10. What will print(type({})) output in Python?

a)
b)
c)
d) SyntaxError
Correct Answer: b)
Explanation:
Empty curly braces {} instantiate an empty dictionary by default in Python. An empty set must be instantiated using set().

11. What is the data type of the expression '5' + '5'?

a) int
b) str
c) float
d) TypeError
Correct Answer: b) str
Explanation:
Concatenating two string objects produces a string object ('55').

12. Which function converts a float or string representation of a number to an integer by truncating decimals?

a) floor()
b) round()
c) int()
d) trunc()
Correct Answer: c) int()
Explanation:
The int() built-in function truncates fractional parts of float arguments towards zero and converts integer strings into int.

13. What is the result of type(True)?

a)
b)
c)
d)
Correct Answer: a)
Explanation:
True is a boolean literal, which belongs to the built-in class 'bool'.

14. In Python, bool is a subclass of which built-in data type?

a) str
b) object
c) int
d) float
Correct Answer: c) int
Explanation:
In Python, bool is explicit subclass of int. True behaves as integer 1 and False behaves as integer 0 in arithmetic operations.

15. Which statement correctly creates a complex number with real part 2 and imaginary part 3?

a) z = 2 + 3i
b) z = 2 + 3j
c) z = complex(2, 3i)
d) z = 2j + 3
Correct Answer: b) z = 2 + 3j
Explanation:
Python uses 'j' or 'J' to denote the imaginary unit component of complex numbers.

16. What is the data type of x = (10)?

a)
b)
c)
d) SyntaxError
Correct Answer: b)
Explanation:
Parentheses surrounding a single item without a trailing comma are interpreted simply as mathematical operator grouping, returning an int.

17. Which syntax correctly defines a single-element tuple?

a) t = (10)
b) t = tuple(10)
c) t = (10,)
d) t = [10],
Correct Answer: c) t = (10,)
Explanation:
A trailing comma is mandatory to distinguish a single-element tuple from standard parenthesized expressions.

18. What is the output of print(isinstance(5.0, int))?

a) True
b) False
c) None
d) TypeError
Correct Answer: b) False
Explanation:
5.0 is an instance of float, not int. Thus, isinstance(5.0, int) returns False.

19. What is the result of sys.getsizeof() or general memory allocation characteristics of Python integers?

a) Fixed 32-bit allocation
b) Fixed 64-bit allocation
c) Arbitrary precision limited only by available memory
d) Maximum ceiling capped at 2^63 - 1
Correct Answer: c) Arbitrary precision limited only by available memory
Explanation:
Python 3 integers have arbitrary precision, meaning they can grow dynamically as large as available system memory permits.

20. What will print(type(None)) display?

a)
b)
c)
d)
Correct Answer: c)
Explanation:
None is the sole instance of the built-in NoneType class, indicating absence of a value.

21. Which of the following is a mutable sequence type in Python?

a) str
b) tuple
c) list
d) bytes
Correct Answer: c) list
Explanation:
Lists are mutable sequence objects, allowing item modifications, additions, and deletions in-place.

22. Which data type represents sequence of immutable Unicode characters?

a) str
b) bytes
c) bytearray
d) char
Correct Answer: a) str
Explanation:
Python 3 'str' objects are immutable sequences of Unicode textual characters.

23. What happens when you execute x, y, z = 1, 2, 3?

a) SyntaxError
b) x, y, and z are assigned values 1, 2, and 3 respectively
c) x gets tuple (1, 2, 3)
d) Only z gets assigned 3
Correct Answer: b) x, y, and z are assigned values 1, 2, and 3 respectively
Explanation:
This demonstrates tuple unpacking in multiple assignments, binding x to 1, y to 2, and z to 3.

24. Which statement about variable names in Python is FALSE?

a) Variable names are case-sensitive.
b) Variable names cannot use Python reserved keywords.
c) Variable names can start with a digit.
d) Variable names can begin with an underscore.
Correct Answer: c) Variable names can start with a digit.
Explanation:
Identifiers/variables in Python cannot start with numbers (0-9).

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

a)
b)
c)
d)
Correct Answer: c)
Explanation:
range() returns an immutable sequence object of class 'range', not a list or generator.

26. Which function returns unique memory address identity integer of a variable?

a) ref()
b) address()
c) id()
d) mem()
Correct Answer: c) id()
Explanation:
id() returns the unique integer identity (memory address in CPython) of an object.

27. Which of these is an immutable mapping type in standard Python?

a) dict
b) mappingproxy / Mapping
c) frozendict
d) Python standard library has no built-in frozendict type
Correct Answer: d) Python standard library has no built-in frozendict type
Explanation:
Unlike standard set/frozenset, Python does not feature a built-in immutable 'frozendict' type in core built-ins.

28. What is the output of print('Hello'[1])?

a) H
b) e
c) l
d) IndexError
Correct Answer: b) e
Explanation:
Python indexing is 0-based. 'Hello'[0] is 'H', so 'Hello'[1] evaluates to 'e'.

29. Which built-in type represents immutable binary data in Python?

a) bytearray
b) bytes
c) memoryview
d) binary
Correct Answer: b) bytes
Explanation:
The 'bytes' class represents immutable sequence streams of 8-bit integers.

30. Which built-in data type represents mutable binary byte arrays?

a) bytes
b) bytearray
c) buffer
d) binary
Correct Answer: b) bytearray
Explanation:
The 'bytearray' class provides a mutable sequence variant of bytes.

31. What is the value of x after x = 3; x += 2 * 4?

a) 20
b) 11
c) 14
d) 24
Correct Answer: b) 11
Explanation:
Multiplication takes precedence: 2 * 4 = 8. Then += adds 8 to 3, assigning 11 to x.

32. What will print(0.1 + 0.2 == 0.3) output in standard Python?

a) True
b) False
c) SyntaxError
d) OverflowError
Correct Answer: b) False
Explanation:
Due to IEEE 754 floating-point binary representation limits, 0.1 + 0.2 yields 0.30000000000000004, making equality False.

33. Which module should be imported for exact fixed-point decimal arithmetic?

a) math
b) float
c) decimal
d) numbers
Correct Answer: c) decimal
Explanation:
The built-in 'decimal' module provides the Decimal data type for exact monetary/decimal math.

34. What is the output of print(type(frozenset([1, 2])))?

a)
b)
c)
d)
Correct Answer: b)
Explanation:
frozenset creates an immutable and hashable variant of a set.

35. What happens if you try to modify a character in a string like s = 'cat'; s[0] = 'b'?

a) s becomes 'bat'
b) TypeError is raised
c) ValueError is raised
d) IndexError is raised
Correct Answer: b) TypeError is raised
Explanation:
Strings are immutable; item assignment on str instances triggers a TypeError.

36. Which keyword allows variables defined in inner functions to modify variables in enclosing scopes?

a) global
b) nonlocal
c) outer
d) super
Correct Answer: b) nonlocal
Explanation:
The 'nonlocal' keyword binds identifiers to variables defined in nearest enclosing scope (excluding globals).

37. What is the data type of the variable assigned via x = b'Hello'?

a) str
b) bytes
c) bytearray
d) unicode
Correct Answer: b) bytes
Explanation:
Prefixing string literals with 'b' creates a 'bytes' object.

38. What will print(type(True + 0)) output?

a)
b)
c)
d) TypeError
Correct Answer: b)
Explanation:
Because bool inherits from int, adding 0 implicitly coerces True (1) to an integer sum 1 of type 'int'.

39. What is the result of type(lambda: None)?

a)
b)
c)
d)
Correct Answer: a)
Explanation:
Lambda expressions create function objects belonging to class 'function'.

40. Which method checks if all characters in a string variable are numeric digits?

a) isnumeric()
b) isdigit()
c) isdecimal()
d) All of the above
Correct Answer: d) All of the above
Explanation:
isdigit(), isnumeric(), and isdecimal() check different subsets of numeric digit characters.

41. What is the output of print(bool([]), bool([0]))?

a) False False
b) False True
c) True True
d) True False
Correct Answer: b) False True
Explanation:
An empty list [] evaluates to False, whereas a non-empty list [0] evaluates to True.

42. Which typing module object indicates a variable can be either an int or float?

a) Union[int, float]
b) int | float
c) Both a and b (in Python 3.10+)
d) Multi[int, float]
Correct Answer: c) Both a and b (in Python 3.10+)
Explanation:
Union[int, float] (from typing) and the bitwise OR syntax 'int | float' (Python 3.10+) denote union type hints.

43. Which expression casts float string '3.14' directly into an integer?

a) int('3.14')
b) int(float('3.14'))
c) cast(int, '3.14')
d) str.to_int('3.14')
Correct Answer: b) int(float('3.14'))
Explanation:
int('3.14') raises ValueError directly. You must parse it to float first, then convert float to int.

44. What will print(type(3 + 4j)) display?

a)
b)
c)
d)
Correct Answer: a)
Explanation:
Numbers expressed with a real component and imaginary 'j' suffix are of type 'complex'.

45. What is the value of complex_num.imag for complex_num = 4 + 7j?

a) 4
b) 7.0
c) 7j
d) 4.0
Correct Answer: b) 7.0
Explanation:
The .real and .imag attributes of complex numbers return floating-point numbers.

46. Which statement about variable scoping is TRUE?

a) Variables defined inside loops are restricted to loop scope.
b) Variables assigned inside functions are local to that function by default.
c) Python uses block scoping similar to C++ and Java.
d) Global variables can be modified inside functions without extra keywords.
Correct Answer: b) Variables assigned inside functions are local to that function by default.
Explanation:
Python features function/module level scoping rather than block scoping for control blocks (if, for, while).

47. What is the output of print(a is b) when a = 256 and b = 256 in standard CPython?

a) True
b) False
c) TypeError
d) SyntaxError
Correct Answer: a) True
Explanation:
CPython caches (interns) small integers in the range [-5, 256], so a and b reference identical memory objects.

48. What is the output of print(a is b) when a = 257 and b = 257 in CPython interactive console?

a) True
b) False
c) None
d) TypeError
Correct Answer: b) False
Explanation:
Integers greater than 256 are not cached as small integers in CPython interactive shell, creating separate memory instances.

49. Which collection variable cannot contain duplicate elements?

a) List
b) Tuple
c) Set
d) Dictionary values
Correct Answer: c) Set
Explanation:
Sets store unique, un-ordered, hashable objects, automatically stripping duplicates.

50. What is the result of type(memoryview(b'abc'))?

a)
b)
c)
d)
Correct Answer: b)
Explanation:
memoryview objects expose buffer protocol interfaces without copying underlying memory bytes.

51. Which data type is used as keys in a dictionary?

a) Any mutable object
b) Any hashable object
c) Only strings
d) Only integers
Correct Answer: b) Any hashable object
Explanation:
Dictionary keys must be hashable (meaning their hash value remains constant, like immutable types int, str, tuple).

52. Can a list be used as a key in a Python dictionary?

a) Yes, always
b) No, because lists are mutable and unhashable
c) Yes, if the list contains only numbers
d) Yes, if converted using list.lock()
Correct Answer: b) No, because lists are mutable and unhashable
Explanation:
Lists are mutable and lack __hash__ definitions, raising a TypeError if used as dictionary keys.

53. What will print(type(10 / 2)) output?

a)
b)
c)
d)
Correct Answer: b)
Explanation:
Division operator '/' always yields a float (5.0), regardless of whether operands divide evenly.

54. What will print(type(10 // 2)) output?

a)
b)
c)
d)
Correct Answer: a)
Explanation:
Floor division (//) on integer operands yields an integer result (5).

55. What is the type of 10.0 // 2?

a)
b)
c)
d) SyntaxError
Correct Answer: b)
Explanation:
Floor division with float operands returns a float result with zero decimal component (5.0).

56. Which statement about Python string immutability is TRUE?

a) String operations modify the original string directly.
b) String operations like replace() or upper() create new string objects.
c) Strings can be modified using slice assignment.
d) Strings can append items using .append().
Correct Answer: b) String operations like replace() or upper() create new string objects.
Explanation:
Because strings are immutable, methods modifying strings return new string objects instead of mutating originals.

57. What is the output of print(f'{10 + 2}')?

a) 10 + 2
b) 12
c) f'12'
d) SyntaxError
Correct Answer: b) 12
Explanation:
Formatted string literals (f-strings) evaluate expressions inside curly braces at runtime and convert to string.

58. Which method returns a shallow copy of a dictionary variable 'd'?

a) d.clone()
b) d.copy()
c) d.shallow()
d) dict.copy(d)
Correct Answer: b) d.copy()
Explanation:
dict.copy() constructs a shallow copy of the target dictionary.

59. What module provides deep copy functionality for variables?

a) copy
b) sys
c) clone
d) std
Correct Answer: a) copy
Explanation:
The standard 'copy' module contains copy.deepcopy() to recursively duplicate nested structures.

60. What is the data type of *args inside a function definition?

a) list
b) tuple
c) dict
d) set
Correct Answer: b) tuple
Explanation:
*args packages extra positional arguments into an immutable tuple.

61. What is the data type of **kwargs inside a function definition?

a) list
b) tuple
c) dict
d) set
Correct Answer: c) dict
Explanation:
**kwargs packages extra named keyword arguments into a standard dictionary.

62. What is the output of bool('False')?

a) False
b) True
c) None
d) ValueError
Correct Answer: b) True
Explanation:
'False' is a non-empty string. Any non-empty string evaluates to True in boolean contexts.

63. What is the result of type(slice(1, 5, 2))?

a)
b)
c)
d)
Correct Answer: b)
Explanation:
slice() constructs slice objects representing indexing ranges [start:stop:step].

64. Which statement correctly swaps values of variables a and b?

a) swap(a, b)
b) a, b = b, a
c) a = b; b = a
d) a.swap(b)
Correct Answer: b) a, b = b, a
Explanation:
Tuple packing and unpacking swaps references atomically without requiring a temporary variable.

65. What is the type of variable x in x = {i: i**2 for i in range(3)}?

a) set
b) dict
c) list
d) tuple
Correct Answer: b) dict
Explanation:
Key: value expression inside curly braces defines a dictionary comprehension.

66. What is the type of variable x in x = {i**2 for i in range(3)}?

a) set
b) dict
c) generator
d) list
Correct Answer: a) set
Explanation:
Single expression within curly braces defines a set comprehension.

67. What is the type of x in x = (i**2 for i in range(3))?

a) tuple
b) generator
c) list
d) iterator
Correct Answer: b) generator
Explanation:
Expressions inside parentheses without list/tuple keywords define generator expressions.

68. What is the default global namespace type accessible via globals()?

a)
b)
c)
d)
Correct Answer: a)
Explanation:
globals() returns a reference to the dictionary representing the current global symbol table.

69. Which of the following creates a variable storing a raw string literal?

a) s = r'Hello\nWorld'
b) s = raw('Hello\nWorld')
c) s = 'Hello\nWorld'.raw()
d) s = #raw 'Hello\nWorld'
Correct Answer: a) s = r'Hello\nWorld'
Explanation:
Prefixing string literals with 'r' or 'R' suppresses escape character evaluation.

70. What will print(r'Hello\nWorld') display?

a) Hello followed by newline World
b) Hello\nWorld
c) HelloWorld
d) SyntaxError
Correct Answer: b) Hello\nWorld
Explanation:
Raw strings treat backslashes '\' as literal characters rather than escape sequences.

71. What is the output of print(type(Ellipsis))?

a)
b)
c)
d)
Correct Answer: a)
Explanation:
Ellipsis (or '...') belongs to the built-in singleton class 'ellipsis'.

72. What is the value of x after x = 10; del x?

a) None
b) 0
c) NameError when accessed
d) False
Correct Answer: c) NameError when accessed
Explanation:
The 'del' statement unbinds variable names; accessing unbound names raises a NameError.

73. What will print(type(int)) output?

a)
b)
c)
d)
Correct Answer: a)
Explanation:
In Python, classes are themselves instances of the metaclass 'type'.

74. Which function converts integer unicode code points into corresponding single-character strings?

a) ord()
b) chr()
c) ascii()
d) str()
Correct Answer: b) chr()
Explanation:
chr(i) returns the string representing character corresponding to Unicode integer i.

75. Which function returns integer Unicode code point corresponding to a character variable?

a) ord()
b) chr()
c) code()
d) val()
Correct Answer: a) ord()
Explanation:
ord(c) returns the integer representation of single Unicode character c.

76. What is the output of ord('A')?

a) 97
b) 65
c) 48
d) 66
Correct Answer: b) 65
Explanation:
The ASCII / Unicode code point integer for uppercase letter 'A' is 65.

77. Which variable typing assignment conforms to official Python 3.6+ variable type annotation syntax?

a) int age = 25
b) age: int = 25
c) age (int) = 25
d) var age: int = 25
Correct Answer: b) age: int = 25
Explanation:
PEP 526 introduced variable type annotations using syntax 'variable: type = value'.

78. Does Python enforce variable type annotations at runtime during code execution?

a) Yes, assignment raises TypeError if types mismatch.
b) No, type hints are ignored at runtime and serve static analyzers.
c) Yes, but only in debug mode.
d) Yes, if typing module is imported.
Correct Answer: b) No, type hints are ignored at runtime and serve static analyzers.
Explanation:
Python remains dynamically typed; type annotations do not raise runtime type errors natively.

79. What is stored in __annotations__ dictionary of a module or class?

a) Variable docstrings
b) Type hints associated with variables and functions
c) Memory addresses
d) Execution logs
Correct Answer: b) Type hints associated with variables and functions
Explanation:
Variable annotations are saved in the __annotations__ attribute dictionary.

80. What is the result of float('inf')?

a) SyntaxError
b) A float representing positive infinity
c) OverflowError
d) ValueError
Correct Answer: b) A float representing positive infinity
Explanation:
float('inf') or float('infinity') parses to floating-point positive infinity.

81. What is the result of type(float('nan'))?

a)
b)
c)
d) ValueError
Correct Answer: a)
Explanation:
NaN (Not a Number) represented by float('nan') is an instance of 'float'.

82. What will print(float('nan') == float('nan')) return?

a) True
b) False
c) TypeError
d) None
Correct Answer: b) False
Explanation:
By IEEE 754 standard specification, NaN is explicitly never equal to any value, including itself.

83. Which math module function correctly checks if float variable 'x' is NaN?

a) math.isnan(x)
b) x == float('nan')
c) x.isnan()
d) type(x) == 'nan'
Correct Answer: a) math.isnan(x)
Explanation:
Because nan == nan returns False, math.isnan() must be used to test for NaN.

84. What is the value of x after x = 5; x **= 2?

a) 10
b) 25
c) 32
d) 7
Correct Answer: b) 25
Explanation:
x **= 2 is shorthand for x = x ** 2 (5 squared equals 25).

85. Which builtin method extracts tuple pair of (quotient, remainder) for numeric variables?

a) divmod()
b) quotrem()
c) math.div()
d) splitmod()
Correct Answer: a) divmod()
Explanation:
divmod(a, b) returns a tuple (a // b, a % b).

86. What is the output of divmod(10, 3)?

a) (3, 1)
b) (1, 3)
c) [3, 1]
d) 3.1
Correct Answer: a) (3, 1)
Explanation:
10 // 3 equals quotient 3, and 10 % 3 equals remainder 1, returned as (3, 1).

87. What is the data type of the result of hex(255)?

a) hex
b) int
c) str
d) bytes
Correct Answer: c) str
Explanation:
The hex() function converts an integer to a lowercase hexadecimal string prefixed with '0x'.

88. What will print(bin(5)) output?

a) '0b101'
b) '101'
c) 101
d) '0x101'
Correct Answer: a) '0b101'
Explanation:
bin() returns binary string representation prefixed with '0b'.

89. Which prefix indicates an octal integer literal in Python?

a) 0o or 0O
b) 0b
c) 0x
d) 0oct
Correct Answer: a) 0o or 0O
Explanation:
Octal integer literals are prefixed with zero and lowercase/uppercase letter 'o' (e.g., 0o10).

90. Which prefix indicates a hexadecimal integer literal in Python?

a) 0x or 0X
b) 0h
c) 0b
d) #
Correct Answer: a) 0x or 0X
Explanation:
Hexadecimal numbers start with prefix '0x' or '0X' (e.g., 0xFF).

91. What is the result of int('101', 2)?

a) 101
b) 5
c) SyntaxError
d) 2
Correct Answer: b) 5
Explanation:
Passing base parameter 2 to int() parses string '101' as binary, returning integer 5.

92. What happens when you pass a float variable to math.trunc()?

a) Rounds to nearest integer
b) Returns integer with fractional part eliminated towards zero
c) Returns float with decimals zeroed out
d) Raises TypeError
Correct Answer: b) Returns integer with fractional part eliminated towards zero
Explanation:
math.trunc() truncates decimals returning real integer value.

93. What is the output of round(2.5) and round(3.5) in Python 3?

a) 3 and 4
b) 2 and 4
c) 2 and 3
d) 3 and 3
Correct Answer: b) 2 and 4
Explanation:
Python 3 uses round-half-to-even (Banker's rounding). 2.5 rounds down to 2 and 3.5 rounds up to 4.

94. What is the result of print(type(zip([1], [2])))?

a)
b)
c)
d)
Correct Answer: b)
Explanation:
zip() returns an iterator object of type 'zip'.

95. Which statement regarding scope of loop variable 'i' in 'for i in range(5): pass' is TRUE?

a) 'i' is destroyed after the loop finishes.
b) 'i' remains accessible in the outer scope with value 4 after loop completion.
c) 'i' remains accessible with value 5.
d) 'i' causes variable leakage error.
Correct Answer: b) 'i' remains accessible in the outer scope with value 4 after loop completion.
Explanation:
For-loops in Python do not create local scope; loop variables persist in surrounding scope.

96. What is the default initial data type returned by input()?

a) int
b) str
c) dynamic depending on entry
d) object
Correct Answer: b) str
Explanation:
The built-in input() function always captures user console input as string.

97. What will print(type(1000000000000000000000000000000)) display in Python 3?

a)
b)
c)
d)
Correct Answer: b)
Explanation:
Python 3 unified int and long types into a single 'int' type supporting arbitrary precision.

98. What does string method string.encode('utf-8') return?

a) str
b) bytes
c) bytearray
d) int list
Correct Answer: b) bytes
Explanation:
Encoding a string converts Unicode str to encoded binary 'bytes'.

99. What does bytes.decode('utf-8') return?

a) str
b) bytes
c) bytearray
d) ASCII
Correct Answer: a) str
Explanation:
Decoding binary bytes converts encoded byte streams back into Unicode text string 'str'.

100. What is the output of print(type(filter(None, [1, 0, 2])))?

a)
b)
c)
d)
Correct Answer: b)
Explanation:
filter() returns a filter object iterator of class 'filter'.

101. Which of the following creates a variable reference copy rather than a shallow or deep data copy?

a) b = a
b) b = a.copy()
c) b = copy.copy(a)
d) b = a[:]
Correct Answer: a) b = a
Explanation:
Simple assignment (b = a) binds b to the exact same object reference in memory.
← Previous: Python Strings MCQs
Next →: Top Python Fundamentals MCQs & Answers for Beginners
NewLatest Python Loops MCQs

Latest Python Loops MCQs

Loops in Python provide the fundamental mechanism for executing a block of code repeatedly until a specified condition is met…

By MCQs Generator
NewPython Functions MCQs

Python Functions MCQs

Functions in Python are reusable blocks of code designed to perform a specific task, promoting code modularity, readability, and DRY…

By MCQs Generator
NewPython Control Flow MCQs

Python Control Flow MCQs

Control flow statements regulate the order in which individual code statements are evaluated and executed in a Python program. Python…

By MCQs Generator