Mission 1.3 - Primitives
In English, words can be categorized as nouns, verbs or adjectives. Just how words are the building blocks to a sentence, primitives are building blocks to a command. Primitives are basic data types that help build larger structures. The four types of primitives in Python are integers (ints), floats, strings and boolean.
First, we will cover ints.
An int in coding is the same as in math- a counting number. These data types are used to represent numeric values. Ex: 1, 52, 315
A float is short for floating point number. This numeric data type is used for rational numbers that are used for decimals. Ex: 3.14, 56.4, 1.78
The next basic data structure is a string. Strings are a collection of letters, numbers, words or other characters. This type is constructed when the collection is enclosed by single or double quotes. Ex. ‘John’, ‘apple’, ‘3.14’, “g2g”
The last primitive is a boolean data type. A boolean data type simply means true or false, which is represented as 1 or 0, respectively. Boolean data types can be used to help the computer make decisions.
If you’re ever unsure of which data type you have, Python has a way to check the type of primitive by writing type(). This is a function which we will explain later in the lessons.