Write Python. Understand every error.

Starting Python in your browser…

Python basics · topic 4 of 25

Data types

Every value in Python has a type, which decides what you can do with it. The four basic types are:

  • int: whole numbers such as 7, -3, 2026
  • float: numbers with a decimal point such as 3.14 or 7.0
  • str: text in quotes such as "hello" or "42"
  • bool: the two truth values True and False

The function type() tells you the type of any value. Notice that "42" is a string, not a number, because it is inside quotes.

print(type(42))
print(type("42"))

You can convert between types with int(), float(), str() and bool(). Converting a float to an int cuts off the decimal part without rounding, so int(7.9) is 7.

The type matters: 5 + 5 is 10, but "5" + "5" is "55", because + joins strings together.

Key takeaways

  • The four basic types are int (whole numbers), float (decimals), str (text) and bool (True or False).
  • "42" in quotes is text, not a number.
  • Convert with int(), float() and str(). int(7.9) gives 7: it cuts off the decimal part and does not round.
  • type(x) tells you what kind of value you have.

Common mistakes

Share this page:

Ctrl + Enter to run
Line 1, column 1Tab indents 4 spaces. Press Esc then Tab to leave the editor.