Let's begin with data types.
A data type is a classification that specifies what type of value something has. We can look at the values of different items and see how they could be the same or different.
Some common data types are
- Int (stands for integer, which is a whole number like 1, 2, 3, etc.)
- Float (a floating point number, a number with a decimal point like 1.56, 26.743, 19.0, etc)
- String (a series of letters/numbers/characters, we put “ “ around our string to contain all of the items, ex “abc”, “sheepshop” “123abc”, “high5”, “c00l~”
- Boolean (either True or False)
We can use the command type to determine the type of something in python. We can use the word type followed by the item in brackets to determine what type it is. Here are some examples:
We can see above that type(3) returned <class 'int'>. This means that 3 has type int, which stands for integer.
Next, type(2.5) returned <class 'float'>. This means that 2.5 has type float, which stands for a floating point number (something with a decimal).
Then, type("hello") returned <class 'str'>. This means that "hello" has type str, which stands for a string (characters contained within quotes).
Finally, type(True) returned <class 'bool'>. This means that True has type bool, which stands for boolean.
You can try for yourself below. Can you find any other data types?