Python Data Types

The core kinds of values

Beginner 9 min

In this lesson

Every value in Python has a type that decides what you can do with it. You’ll meet the core types and learn to check any value’s type with type().

Explain it like I’m 5

Values come in different shapes: text, whole numbers, decimals, true/false, and collections. The type is the shape, and the shape decides what operations make sense.

The everyday types

  • str — text, in quotes: "hi"
  • int — whole numbers: 42
  • float — decimals: 3.14
  • boolTrue or False
  • list — an ordered collection: [1, 2, 3]
  • dict — key→value pairs: {"a": 1}
  • NoneType — the single value None, meaning ‘no value’

You’ll get a dedicated lesson on each of these. For now, just recognise them.

Checking a type with type()

type(value) tells you the type of any value. This is genuinely useful when debugging: a surprising bug is often a value that’s a different type than you assumed (for example, text "5" where you expected the number 5).

Example
print(type("hi"))
print(type(5))
print(type(3.14))
print(type(True))
Output
<class 'str'>
<class 'int'>
<class 'float'>
<class 'bool'>
Checking several values’ types.

Print the type of three different values: a string, an int, and a float. Then try type([1, 2, 3]).

print(type("text"))
print(type(10))
print(type(2.5))

Why types matter

Operations depend on type. + adds numbers but joins strings, so 2 + 2 is 4 while "2" + "2" is "22". Mixing incompatible types ("2" + 2) raises a TypeError. Knowing the type tells you what’s allowed.

Example
print(2 + 2)
print("2" + "2")
Output
4
22
The same + behaves differently by type.
Example
quantity = "5"
print(type(quantity))
number = int(quantity)
print(type(number), number + 1)
Output
<class 'str'>
<class 'int'> 6
Converting text to a number so you can do maths.

Converting between types

You’ll constantly need to turn one type into another, and the tools are named after the target type: int() makes a whole number, str() makes text, float() makes a decimal, and bool() makes a True/False. So int("5") gives the number 5, and str(42) gives the text "42".

Conversion only works when it makes sense: int("hello") can’t become a number and raises an error. Recognising and handling those is its own skill — learn more about common errors here.

Example
print(int("5") + 1)
print(str(42) + "!")
print(float("3.14"))
print(bool(""), bool("hi"))
Output
6
42!
3.14
False True
Each function converts to the type it’s named after.

What type is the value 3.0?

What does "2" + "3" produce?

Mini exercise (medium)

Create a variable holding the text "10", convert it to an integer, and print the integer plus 5.

Do it here. Finish the code below and press Run to try your answer right in the browser — no setup needed.

text = "10"
number = 0      # TODO: convert text to an integer
print(number + 5)

What to learn next

You met Python’s everyday built-in types (str, int, float, bool, list, dict, and None), learned to inspect any value with type(), and saw why types matter. You applied it by converting the text “10” into a real integer and doing maths with it.

The next few lessons take those types one at a time, starting with the one you’ll handle constantly: text. Strings covers quotes and escaping, indexing and slicing, the most useful string methods, and what it means that strings are immutable. When you’re ready, continue to the next lesson.