There are four essential types of data you can represent and that can be stored in variables when coding a computer program. Although variables in the Python language can store any type of data it is important to understand the different types as you will sometimes need to convert from one type to another in your code:
- Strings are simply any collection of characters you can enter from the computer keyboard, grouped together within quote marks.
- Variables recognize a value being assigned to it as belonging to the str “class” if that value is enclosed within quote marks.
- Numbers are any numeric value you can enter from the keyboard but are defined by the inclusion or omission of a decimal point. Variables recognize a numeric value being assigned to it as belonging to the int “class” if that value has no decimal point or as belonging to the float class if it does indeed have a decimal point.
- Booleans are a logical truth value. Variables recognize a Boolean value being assigned to it as belonging to the bool “class” by the keywords True and False, or if that value evaluates to True or False.
In Python programming you can easily discover the type of data stored within a variable by specifying that variable’s name within the parentheses of the built-in type() function.
This extract is from Coding for Beginners in easy steps. Get the book and learn a new skill!
By Mike McGrath