🏷️ Data Type

5th Grade 💻 Coding

A data type is the kind of value something is: a whole number, a decimal number, text (a string), true/false (a Boolean), a list and more. The type decides what you can do with the value.

Free · US Letter · no sign-up
Google Classroom Save to Pinterest Email me

Numbers can be added, multiplied and divided. Text can be stuck together and you can count its letters. A Boolean value can be flipped with not. When you mix types without paying attention, you get surprises: "5" + "5" gives "55", and "5" + 5 in Python gives an error.

In Python, the type function tells you the type: type(3.5) gives float (a decimal number), and type("5") gives str (a string). You can convert between types: int("12") turns the text "12" into the number 12, and str(7) turns the number 7 into text.

For example

  • Your age is a whole number (11), your height in feet is a decimal number (4.75), your name is a string ("Noah"), and “Do I have a brother?” is a Boolean.
  • In Python, input always gives back a string, so you convert a typed-in age to a number with int before doing math with it.

📌 Remember: Every value has a type — and the type decides what you’re allowed to do with it.

Quick quiz

  1. What is a data type?

  2. What does type(3.5) give in Python?

  3. What does int("12") do?

🔎 Ask Thinkapedia another question