Python Data Types Explained: Concepts, Conversions and Exam-Style Output Tracing
Learn how Python names, objects and built-in types work, then trace conversions, division, list aliasing and shallow copying through an exact program.
KnowledgeGate Team
Exam prep & CS education

Learners often memorise names such as int, float and list, but output questions combine conversion, operator result types and mutability in one trace. Python objects and types follow a clear model, and the program's printed values and types are fixed.
Use Python Tokens, Variables, Data Types and I/O when a question starts at lexical tokens or keyboard input, Introduction to Python for control flow and functions, and Python Operators and Expressions for precedence or short-circuiting. For data-type questions, classify the object family, conversion result, mutability, identity and hashability before tracing aliases.
Python data types: variables name objects
A data type describes the values and operations an object supports. Python variables are names bound to objects. x = 12 binds x to an int, while a later x = "12" rebinds the same name to a str. The name is not permanently declared as one type.
When reading a program line by line, keep source code text separate from the runtime objects created and rebound as each expression is evaluated.
Use type() when you need the exact type and isinstance() when subclasses should count. These checks have precise results:
type(12).__name__ == "int" # True
isinstance(12, int) is True # True
isinstance(True, int) is True # TrueThe last result is intentional because bool subclasses int.
Built-in data types: scalar, sequence, mapping and set
Built-in data types fall into scalar, sequence, mapping, set and binary families.
Family | Types | Exact example | Mutable? |
|---|---|---|---|
Numeric and singleton |
|
| No |
Sequence |
|
| Only |
Mapping |
|
| Yes |
Set |
|
| Only |
Binary |
|
| Only |
Lists, dictionaries, sets and bytearrays can change in place. Integers, floats, complex numbers, booleans, None, strings, tuples, ranges, frozensets and bytes cannot. An immutable tuple can still contain a mutable object, as in ([7, 2], "score"); the inner list can change. If these foundations feel shaky beyond Python, the Coding & Skill Development Courses catalogue maps the broader Python, C, Java and DSA sequence.

Type conversion and operator result types
An explicit conversion calls a type, while an operator applies its result rules. With 7 and 2, true division 7 / 2 produces 3.5 of type float; floor division 7 // 2 produces 3 of type int.
Conversions must match the input text:
int("10")produces integer10.float("3.5")produces floating-point3.5.int(3.9)produces3by truncating towards zero.int("3.5")raisesValueError. Usefloat("3.5")first when the input represents a decimal.
For bases, int("101", 2) produces 5; Number Systems and Base Conversions Explained develops the place-value method. Many decimal fractions lack an exact finite binary representation, as Floating Point Representation: IEEE 754 Format explains.
Truth conversion follows emptiness, not the human meaning of text. bool("") is False, but bool("0") and bool("False") are both True because both strings are non-empty.
Mutability, identity and hashability
With data = [7, 3.5, 3], alias = data and copy = data[:], the first two names point to one list. Slicing creates a separate shallow list, so changing alias[0] appears through data, but not copy.
Identity asks whether two names refer to the same object; equality asks whether their values compare equal. Before any change, alias is data is True, copy is data is False, and copy == data is True.
Immutable values are commonly safe dictionary keys because their hash does not change. {(7, 2): "pair"} is valid, but {[7, 2]: "pair"} raises TypeError because lists are unhashable. A tuple is hashable only if every element is hashable, so {([7, 2],): "pair"} also raises TypeError.
Worked Python trace: division, conversion and aliasing
Trace this program in statement order:
x = 7
y = 2
quotient = x / y
floor = x // y
data = [x, quotient, floor]
alias = data
copy = data[:]
alias[0] = int("10")
copy.append(bool(""))
print(data)
print(copy)
print(type(quotient).__name__)First, x / y evaluates to 3.5, a float, while x // y evaluates to 3, an int. Therefore data is initially [7, 3.5, 3].
Next, alias = data binds a second name to the list. copy = data[:] creates a new list with the same element references, so it also starts as [7, 3.5, 3]. This slice is shallow, but all three elements are immutable scalars, so no nested mutable object changes the result.
int("10") evaluates to 10. Assigning it through alias[0] changes the shared list to [10, 3.5, 3]; the separate copy keeps 7.
Finally, bool("") is False, and appending it changes only copy. The output is exactly:
[10, 3.5, 3]
[7, 3.5, 3, False]
float
Common data type traps and their corrections
Reading a string by its human meaning:
bool("False")isTruebecause truth testing sees a non-empty string. If the word matters, normalise and compare the text explicitly, for exampletext.strip().lower() == "true".Treating booleans and integers as the same exact type:
True == 1andTrue + 2 == 3, becauseboolsubclassesint. Still,type(True) is boolandtype(1) is int. Check whether the question asks about compatibility or exact type.Assuming sets preserve duplicates or display order:
set([2, 2, 3])contains the values2and3once each. Never depend on set iteration order unless the question adds an ordering operation such assorted(...).Calling every tuple hashable: a tuple containing a list is unhashable because the list is unhashable.
Treating slicing as a recursive copy:
data[:]makes a new outer list, but nested mutable objects would still be shared.
How exam questions test data types
Exam-style questions ask you to trace how expressions produce values and types, then follow what happens to objects. You may predict the exact output, spot a conversion that fails, distinguish mutation from rebinding, follow aliases, or judge whether an object can be a dictionary key.
Try this complete output question.
n = 7
m = 2
kind = type(n / m).__name__
items = [n, n // m]
mirror = items
mirror.append(bool(""))
print(items, kind)What does the program print?
(a)
[7, 3] float(b)
[7, 3, False] float(c)
[7, 3, False] int(d)
[7, 3, True] float
Answer: (b). n / m is 3.5, so kind is "float", while n // m is 3, making items equal to [7, 3]. mirror aliases that list, so appending bool(""), which is False, changes the list seen through items.
The short version and next step
Use this five-point revision checklist:
Identify the current object and its type.
Evaluate explicit conversions before the surrounding operators.
Track which objects are mutable.
Draw alias arrows when two names share an object.
Compute each print line in order.
If you want the topic sequence together with MCQs and coding practice, Python Course: Concepts, MCQs & Coding is the focused next step. If you only need this concept, keep tracing small programs by hand and confirm them in a Python interpreter.
For one final practice change, replace copy = data[:] with copy = data in the worked program. Predict why both final list outputs then come from the same object.
Keep learning

OOP Basics in Python: Classes, Objects and Inheritance with Examples
Build one Python BankAccount program step by step, then use it to understand object state, validation, inheritance and runtime method selection.

Itertools in Python: Lazy Iterators, Pipelines and Worked Examples
Learn how Python's itertools builds readable, lazy pipelines. Runnable examples cover infinite iterators, filtering, running totals, adjacent pairs, tee, combinations and groupby.

File Handling in Python: Read, Write, Append, CSV and Binary Examples
Learn a reliable file-handling workflow through one scores file, then apply it to cursor control, append mode, CSV quoting, binary records and common errors.

Decorators in Python: @ Syntax, Wrappers and Worked Examples
Understand when decoration happens, what a wrapper receives, and how return values travel back. Runnable examples cover parameters, stacking and built-ins.

