3. Python Data Types
Python Data Types
Every value in Python has a data type. The data type tells Python what kind of information is being stored and what operations are allowed on it. You cannot, for example, add a number to a piece of text without converting it first.
Python has a rich set of built-in data types organized into several categories. Understanding them is fundamental to writing programs that behave correctly.
The Core Built-in Types
Python's most commonly used data types are organized into these groups:
- Text — str (string)
- Numeric — int (integer), float (decimal), complex (complex number)
- Sequence — list, tuple, range
- Mapping — dict (dictionary)
- Set — set, frozenset
- Boolean — bool (True or False)
- Binary — bytes, bytearray
- None — NoneType (represents the absence of a value)
Strings (str)
A string is a sequence of characters enclosed in either single quotes or double quotes. Strings are used to represent text — names, messages, file paths, anything written.
You can use either single or double quotes — Python treats them identically. The key rule is to be consistent within the same string.
Integers (int)
An integer is a whole number with no decimal point. It can be positive, negative, or zero. There is no size limit to Python integers — they can grow as large as your computer's memory allows.
Floats (float)
A float is a number that contains a decimal point. Floats are used whenever you need precision — prices, measurements, scientific calculations, percentages.
Floats can also be written in scientific notation using the letter e. For example, 1.5e3 means 1.5 × 10³ = 1500.0.
Booleans (bool)
A boolean represents one of only two possible values: True or False. Booleans are the foundation of all decision-making in programming — every if-statement, every while-loop, every comparison ultimately resolves to True or False.
In Python, True and False must be capitalized exactly. true or false in lowercase will cause a NameError.
NoneType
None is a special constant in Python that represents the absence of a value. It is not zero, not an empty string, not False — it is the deliberate absence of any value whatsoever. Functions that do not explicitly return a value automatically return None.
Knowledge Check
Ready to test your understanding of 3. Python Data Types?