# Data Types in Python

> The kinds of value a program works with: whole numbers, decimals, text, true or false, and None. Why 0.1 + 0.2 is not quite 0.3.

**Course:** [Programming Basics](https://learn.benibix.com/learn/development-concepts)  
**Time:** 12 min

**After this lesson you can:**

- Name the basic data types in Python
- Explain why decimals can be slightly off
- Tell None apart from zero and empty text

## What kinds of value a program can hold

Every value has a data type: the kind of value it is. Python's main ones are whole numbers, decimal numbers, text, and true or false. The type decides what you can do. You can multiply two numbers, but you cannot multiply two words. Ask Python with type(7) and it answers int.

An integer is a whole number, such as 7, 0 or -12. In Python it is called int. Python integers can grow as big as memory allows, so 2 ** 100 works fine. Dividing two integers with / gives a decimal, so 7 / 2 gives 3.5. Use // to keep only the whole part, which gives 3.

A floating-point number is a number with a decimal part, such as 3.5. In Python it is called float. A float keeps about 15 to 17 digits, so it is close but not always exact. Type 0.1 + 0.2 and Python prints 0.30000000000000004. For money, people often count in whole cents instead.

A string is a piece of text, written inside quote marks, such as "Emma" or 'hello'. In Python it is called str. A string can hold one letter, a whole page, or nothing at all, written as "". Note that "42" in quote marks is text, not a number.

A boolean holds only one of two values, True or False. In Python it is called bool, and the capital letter matters. Booleans answer yes or no questions, such as is the cart empty. Every if test you will write later works out to one of them.

Null means no value at all. Python spells it None. It is not 0 and it is not empty text. A variable holding None is saying there is nothing here yet, such as a phone number a user never gave. Many crashes come from treating None as if it were a real value.

Underneath, every value is stored as bytes. A byte is 8 bits, and each bit is a 0 or a 1, so one byte has 256 possible values, from 0 to 255. The letter A takes 1 byte in most text files. File sizes and memory are both measured in bytes.

## The basic data types in Python

| Type | Python name | Examples |
| --- | --- | --- |
| Integer | int | 7, 0, -12 |
| Floating-point number | float | 3.5, 0.1, -2.0 |
| String | str | "Emma", "42", "" |
| Boolean | bool | True, False |
| Null | NoneType | None |

![Five labelled boxes in a row: int holding 7, float holding 3.5, str holding the text Emma in quote marks, bool holding True, and None holding an empty dashed outline marked no value.](https://learn.benibix.com/diagrams/prog-data-types.svg)

### Example: Emma's price total is off by a hair

Emma's till adds 0.10 and 0.20 and shows 0.30000000000000004. Her test expects exactly 0.3 and fails.

She changes the program to store prices in cents, as integers: 10 and 20. The total is exactly 30, and she divides by 100 only when she shows it.

**Words in this lesson:** [Data Type](https://learn.benibix.com/term/development/data-type), [Integer](https://learn.benibix.com/term/development/integer), [Floating-Point Number](https://learn.benibix.com/term/development/floating-point-number), [String](https://learn.benibix.com/term/development/string), [Boolean](https://learn.benibix.com/term/development/boolean), [Null](https://learn.benibix.com/term/development/null), [Byte](https://learn.benibix.com/term/development/byte)

**Question:** Why does 0.1 + 0.2 not give exactly 0.3 in Python?

**Answer:** Floats keep a close value, not always an exact one. A float stores about 15 to 17 digits, so some decimals are kept as a very close value. Tiny gaps like this show up when you add them.

---

Source: https://learn.benibix.com/learn/development-concepts/data-types-in-python
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
