An Introduction to Programming

Python for All

Chapter Five — Data Types Deep Dive

Thanasis Troboukis  ·  All Chapters

Chapter Five

Data Types Deep Dive

Understand what each Python data type is, when to use it, and how to inspect values confidently.

Data Type Map

Every value in Python has a type. A type tells Python what that value is and what you can do with it. The most important groups are:

Numeric: int, float (and complex, which we will skip for now)
Boolean: True, False
String: text values like "hello"
Collections: list, tuple, set, dict

Python · Try it

      

Numeric Types

Python also has complex numbers, but we will not be dealing with complex numbers in this course.

int — whole numbers

Integers have no decimal point. Use them for counting and indexing.

Python · Try it

      

float — decimal numbers

Floats store values with decimals.

Python · Try it

      

Strings, Booleans, and None

str — text

Strings are text values inside quotes. You can combine and slice them.

Python · Try it

      

bool — True or False

Booleans represent logical answers: yes/no, pass/fail, on/off.

Python · Try it

      

NoneType — no value yet

None is used when a variable has no meaningful value yet.

Python · Try it

      

Collection Types

Collection types hold multiple values, but each one behaves differently.

list — ordered and changeable

A list keeps items in order, allows duplicates, and can be modified after creation. Use a list when order matters and you expect to add, remove, or update items.

You access list items by index: 0 is the first item, 1 is the second, and so on.

Python · Try it

      

tuple — ordered and fixed

A tuple is like a list that cannot be changed after creation. It keeps order, allows duplicates, and supports indexing.

Use tuples for values that should stay constant, such as coordinates, RGB colors, or fixed settings.

Python · Try it

      

set — unique values, no order

A set stores unique values only. If you add the same value more than once, it appears only once.

Sets are useful for removing duplicates and for fast membership checks like if "python" in tags.

Common methods: .add(value) to insert, .remove(value) to delete (error if missing), .discard(value) to delete safely (no error if missing), and .pop() to remove and return one arbitrary item.

Python · Try it

      

dict — key/value pairs

A dictionary stores data as key: value pairs. You use a key (label) to access its value.

Use dictionaries when each value has a meaningful name, such as student attributes, settings, or lookup tables.

Common methods: .get(key) for safe reading, .keys() and .values() to inspect data, .items() to loop key/value pairs, .update({...}) to add new key/value pairs or change existing ones, and .pop(key) to remove one key and return its value.

Python · Try it

      
Quick memory tip: list is ordered and editable, tuple is ordered and fixed, set keeps only unique values, and dict stores labeled data with keys.

Chapter Navigation

Move between chapters.

Loading Python environment — this may take a moment…