Skip to content
BENIBIX Learn

Data Type

Development🧩 Programming ConceptsData and Variables

Also known as Type

The kind of value something is. A number, a bit of text, or true or false.

Think of it like

Think of it like the kind of thing in a jar. Sugar, nails and water each need their own jar.

Example

Jack adds "5" + 5 in Python and gets an error. One is text and one is a number, so Python will not mix them.

Why it matters

Many bugs come from a value of the wrong type. Knowing the type tells you which actions are safe.

Definition

A data type says what kind of value something is. Whole numbers, decimals, text and true or false are the common ones. The type decides what you can do with the value. You can add two numbers, but you cannot add a number to a word without changing one first. Each language has its own names for its types.

Example code

python
>>> type(42)
<class 'int'>
>>> "5" + 5
TypeError: can only concatenate str (not "int") to str
Python knows 42 is a whole number, and refuses to add text to it.

Common mistake

Thinking "5" and 5 are the same. One is text that looks like a number; the other is a number.

Key takeaways

  1. 1
    Kind of value. Number, text and true or false differ.
  2. 2
    Decides the actions. Each type allows its own set of moves.
  3. 3
    Convert on purpose. Change a type yourself before mixing them.

Learn it properly