🧩Data Type
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
Example code
python
>>> type(42)
<class 'int'>
>>> "5" + 5
TypeError: can only concatenate str (not "int") to strCommon mistake
Key takeaways
- 1Kind of value. Number, text and true or false differ.
- 2Decides the actions. Each type allows its own set of moves.
- 3Convert on purpose. Change a type yourself before mixing them.