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

Updated 28 Oct 20266 min read

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:

python
type(12).__name__ == "int"       # True
isinstance(12, int) is True      # True
isinstance(True, int) is True    # True

The 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

int, float, complex, bool, NoneType

12, 3.5, 2 + 3j, True, None

No

Sequence

str, list, tuple, range

"GATE", [7, 2], (7, 2), range(3)

Only list

Mapping

dict

{"score": 7}

Yes

Set

set, frozenset

{2, 7}, frozenset({2, 7})

Only set

Binary

bytes, bytearray

b"KG", bytearray(b"KG")

Only bytearray

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.

A Python type map grouping immutable objects (int, float, str) against mutable ones, with two names bound to one list versus a separate copy.

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 integer 10.

  • float("3.5") produces floating-point 3.5.

  • int(3.9) produces 3 by truncating towards zero.

  • int("3.5") raises ValueError. Use float("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:

python
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:

Code
[10, 3.5, 3]
[7, 3.5, 3, False]
float
A four-frame trace of the worked program: int and float results, two names sharing one list, a separate copy, and how mutations change them.

Common data type traps and their corrections

  • Reading a string by its human meaning: bool("False") is True because truth testing sees a non-empty string. If the word matters, normalise and compare the text explicitly, for example text.strip().lower() == "true".

  • Treating booleans and integers as the same exact type: True == 1 and True + 2 == 3, because bool subclasses int. Still, type(True) is bool and type(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 values 2 and 3 once each. Never depend on set iteration order unless the question adds an ordering operation such as sorted(...).

  • 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.

python
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:

  1. Identify the current object and its type.

  2. Evaluate explicit conversions before the surrounding operators.

  3. Track which objects are mutable.

  4. Draw alias arrows when two names share an object.

  5. 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.