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.
Python Variables & Data Types MCQs
1 min read
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.
Correct Answer: b) type()
Explanation:
The built-in type() function returns the exact data type of the specified variable or object.
Correct Answer: d) Tuple
Explanation:
Tuples are immutable sequence types in Python; once initialized, their elements cannot be changed, added, or removed.
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.
Correct Answer: a) <class 'int'>
Explanation:
Python allows underscores in numeric literals as visual grouping separators. The value 1_000_000 is parsed purely as an integer 1000000.
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'.
Correct Answer: b) False, True
Explanation:
The integer 0 evaluates to False in boolean context, whereas any non-zero numeric value evaluates to True.
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.
Correct Answer: b) <class 'set'>
Explanation:
Curly braces containing comma-separated values without colon key-value pairs define a set object.
Correct Answer: b) <class 'dict'>
Explanation:
Empty curly braces {} instantiate an empty dictionary by default in Python. An empty set must be instantiated using set().
Correct Answer: b) str
Explanation:
Concatenating two string objects produces a string object ('55').
Correct Answer: c) int()
Explanation:
The int() built-in function truncates fractional parts of float arguments towards zero and converts integer strings into int.
Correct Answer: a) <class 'bool'>
Explanation:
True is a boolean literal, which belongs to the built-in class 'bool'.
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.
Correct Answer: b) z = 2 + 3j
Explanation:
Python uses 'j' or 'J' to denote the imaginary unit component of complex numbers.
Correct Answer: b) <class 'int'>
Explanation:
Parentheses surrounding a single item without a trailing comma are interpreted simply as mathematical operator grouping, returning an int.
Correct Answer: c) t = (10,)
Explanation:
A trailing comma is mandatory to distinguish a single-element tuple from standard parenthesized expressions.
Correct Answer: b) False
Explanation:
5.0 is an instance of float, not int. Thus, isinstance(5.0, int) returns False.
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.
Correct Answer: c) <class 'NoneType'>
Explanation:
None is the sole instance of the built-in NoneType class, indicating absence of a value.
Correct Answer: c) list
Explanation:
Lists are mutable sequence objects, allowing item modifications, additions, and deletions in-place.
Correct Answer: a) str
Explanation:
Python 3 'str' objects are immutable sequences of Unicode textual characters.
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.
Correct Answer: c) Variable names can start with a digit.
Explanation:
Identifiers/variables in Python cannot start with numbers (0-9).
Correct Answer: c) <class 'range'>
Explanation:
range() returns an immutable sequence object of class 'range', not a list or generator.
Correct Answer: c) id()
Explanation:
id() returns the unique integer identity (memory address in CPython) of an object.
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.
Correct Answer: b) e
Explanation:
Python indexing is 0-based. 'Hello'[0] is 'H', so 'Hello'[1] evaluates to 'e'.
Correct Answer: b) bytes
Explanation:
The 'bytes' class represents immutable sequence streams of 8-bit integers.
Correct Answer: b) bytearray
Explanation:
The 'bytearray' class provides a mutable sequence variant of bytes.
Correct Answer: b) 11
Explanation:
Multiplication takes precedence: 2 * 4 = 8. Then += adds 8 to 3, assigning 11 to x.
Correct Answer: b) False
Explanation:
Due to IEEE 754 floating-point binary representation limits, 0.1 + 0.2 yields 0.30000000000000004, making equality False.
Correct Answer: c) decimal
Explanation:
The built-in 'decimal' module provides the Decimal data type for exact monetary/decimal math.
Correct Answer: b) <class 'frozenset'>
Explanation:
frozenset creates an immutable and hashable variant of a set.
Correct Answer: b) TypeError is raised
Explanation:
Strings are immutable; item assignment on str instances triggers a TypeError.
Correct Answer: b) nonlocal
Explanation:
The 'nonlocal' keyword binds identifiers to variables defined in nearest enclosing scope (excluding globals).
Correct Answer: b) bytes
Explanation:
Prefixing string literals with 'b' creates a 'bytes' object.
Correct Answer: b) <class 'int'>
Explanation:
Because bool inherits from int, adding 0 implicitly coerces True (1) to an integer sum 1 of type 'int'.
Correct Answer: a) <class 'function'>
Explanation:
Lambda expressions create function objects belonging to class 'function'.
Correct Answer: d) All of the above
Explanation:
isdigit(), isnumeric(), and isdecimal() check different subsets of numeric digit characters.
Correct Answer: b) False True
Explanation:
An empty list [] evaluates to False, whereas a non-empty list [0] evaluates to True.
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.
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.
Correct Answer: a) <class 'complex'>
Explanation:
Numbers expressed with a real component and imaginary 'j' suffix are of type 'complex'.
Correct Answer: b) 7.0
Explanation:
The .real and .imag attributes of complex numbers return floating-point numbers.
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).
Correct Answer: a) True
Explanation:
CPython caches (interns) small integers in the range [-5, 256], so a and b reference identical memory objects.
Correct Answer: b) False
Explanation:
Integers greater than 256 are not cached as small integers in CPython interactive shell, creating separate memory instances.
Correct Answer: c) Set
Explanation:
Sets store unique, un-ordered, hashable objects, automatically stripping duplicates.
Correct Answer: b) <class 'memoryview'>
Explanation:
memoryview objects expose buffer protocol interfaces without copying underlying memory bytes.
Correct Answer: b) Any hashable object
Explanation:
Dictionary keys must be hashable (meaning their hash value remains constant, like immutable types int, str, tuple).
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.
Correct Answer: b) <class 'float'>
Explanation:
Division operator '/' always yields a float (5.0), regardless of whether operands divide evenly.
Correct Answer: a) <class 'int'>
Explanation:
Floor division (//) on integer operands yields an integer result (5).
Correct Answer: b) <class 'float'>
Explanation:
Floor division with float operands returns a float result with zero decimal component (5.0).
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.
Correct Answer: b) 12
Explanation:
Formatted string literals (f-strings) evaluate expressions inside curly braces at runtime and convert to string.
Correct Answer: b) d.copy()
Explanation:
dict.copy() constructs a shallow copy of the target dictionary.
Correct Answer: a) copy
Explanation:
The standard 'copy' module contains copy.deepcopy() to recursively duplicate nested structures.
Correct Answer: b) tuple
Explanation:
*args packages extra positional arguments into an immutable tuple.
Correct Answer: c) dict
Explanation:
**kwargs packages extra named keyword arguments into a standard dictionary.
Correct Answer: b) True
Explanation:
'False' is a non-empty string. Any non-empty string evaluates to True in boolean contexts.
Correct Answer: b) <class 'slice'>
Explanation:
slice() constructs slice objects representing indexing ranges [start:stop:step].
Correct Answer: b) a, b = b, a
Explanation:
Tuple packing and unpacking swaps references atomically without requiring a temporary variable.
Correct Answer: b) dict
Explanation:
Key: value expression inside curly braces defines a dictionary comprehension.
Correct Answer: a) set
Explanation:
Single expression within curly braces defines a set comprehension.
Correct Answer: b) generator
Explanation:
Expressions inside parentheses without list/tuple keywords define generator expressions.
Correct Answer: a) <class 'dict'>
Explanation:
globals() returns a reference to the dictionary representing the current global symbol table.
Correct Answer: a) s = r'Hello\nWorld'
Explanation:
Prefixing string literals with 'r' or 'R' suppresses escape character evaluation.
Correct Answer: b) Hello\nWorld
Explanation:
Raw strings treat backslashes '\' as literal characters rather than escape sequences.
Correct Answer: a) <class 'ellipsis'>
Explanation:
Ellipsis (or '...') belongs to the built-in singleton class 'ellipsis'.
Correct Answer: c) NameError when accessed
Explanation:
The 'del' statement unbinds variable names; accessing unbound names raises a NameError.
Correct Answer: a) <class 'type'>
Explanation:
In Python, classes are themselves instances of the metaclass 'type'.
Correct Answer: b) chr()
Explanation:
chr(i) returns the string representing character corresponding to Unicode integer i.
Correct Answer: a) ord()
Explanation:
ord(c) returns the integer representation of single Unicode character c.
Correct Answer: b) 65
Explanation:
The ASCII / Unicode code point integer for uppercase letter 'A' is 65.
Correct Answer: b) age: int = 25
Explanation:
PEP 526 introduced variable type annotations using syntax 'variable: type = value'.
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.
Correct Answer: b) Type hints associated with variables and functions
Explanation:
Variable annotations are saved in the __annotations__ attribute dictionary.
Correct Answer: b) A float representing positive infinity
Explanation:
float('inf') or float('infinity') parses to floating-point positive infinity.
Correct Answer: a) <class 'float'>
Explanation:
NaN (Not a Number) represented by float('nan') is an instance of 'float'.
Correct Answer: b) False
Explanation:
By IEEE 754 standard specification, NaN is explicitly never equal to any value, including itself.
Correct Answer: a) math.isnan(x)
Explanation:
Because nan == nan returns False, math.isnan() must be used to test for NaN.
Correct Answer: b) 25
Explanation:
x **= 2 is shorthand for x = x ** 2 (5 squared equals 25).
Correct Answer: a) divmod()
Explanation:
divmod(a, b) returns a tuple (a // b, a % b).
Correct Answer: a) (3, 1)
Explanation:
10 // 3 equals quotient 3, and 10 % 3 equals remainder 1, returned as (3, 1).
Correct Answer: c) str
Explanation:
The hex() function converts an integer to a lowercase hexadecimal string prefixed with '0x'.
Correct Answer: a) '0b101'
Explanation:
bin() returns binary string representation prefixed with '0b'.
Correct Answer: a) 0o or 0O
Explanation:
Octal integer literals are prefixed with zero and lowercase/uppercase letter 'o' (e.g., 0o10).
Correct Answer: a) 0x or 0X
Explanation:
Hexadecimal numbers start with prefix '0x' or '0X' (e.g., 0xFF).
Correct Answer: b) 5
Explanation:
Passing base parameter 2 to int() parses string '101' as binary, returning integer 5.
Correct Answer: b) Returns integer with fractional part eliminated towards zero
Explanation:
math.trunc() truncates decimals returning real integer value.
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.
Correct Answer: b) <class 'zip'>
Explanation:
zip() returns an iterator object of type 'zip'.
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.
Correct Answer: b) str
Explanation:
The built-in input() function always captures user console input as string.
Correct Answer: b) <class 'int'>
Explanation:
Python 3 unified int and long types into a single 'int' type supporting arbitrary precision.
Correct Answer: b) bytes
Explanation:
Encoding a string converts Unicode str to encoded binary 'bytes'.
Correct Answer: a) str
Explanation:
Decoding binary bytes converts encoded byte streams back into Unicode text string 'str'.
Correct Answer: b) <class 'filter'>
Explanation:
filter() returns a filter object iterator of class 'filter'.
Correct Answer: a) b = a
Explanation:
Simple assignment (b = a) binds b to the exact same object reference in memory.
Related Posts
New
New
New

JavaScript Asynchronous Programming
Asynchronous programming in JavaScript enables non-blocking execution, allowing long-running operations such as network requests, file reading, or timers to run…
August 29, 2026By MCQs Generator

Python OOP MCQs
Object-Oriented Programming (OOP) in Python is a programming paradigm that uses classes and objects to model real world entities, promoting…
August 27, 2026By MCQs Generator

JavaScript DOM Manipulation MCQs
The Document Object Model (DOM) is a cross-platform programming interface that treats HTML and XML documents as a hierarchical tree…
August 29, 2026By MCQs Generator
Related Categories

AI & Data Science MCQ
5 topics
By MCQs Generator

Arts & Humanities MCQ
4 topics
By MCQs Generator

Civil Engineering MCQ
4 topics
By MCQs Generator

Commerce & Business MCQ
4 topics
By MCQs Generator

Competitive Exams MCQ
5 topics
By MCQs Generator

Electrical & Electronics Engineering MCQ
3 topics
By MCQs Generator

General Knowledge MCQ
2 topics
By MCQs Generator

General Science MCQ
4 topics
By MCQs Generator

Law & Judiciary MCQ
3 topics
By MCQs Generator

Mechanical Engineering MCQ
4 topics
By MCQs Generator

Medical & Health Sciences MCQ
4 topics
By MCQs Generator

Modern Tech Fields MCQ
3 topics
By MCQs Generator