primitive data types
In programming, we call a single piece of data a value. A data type is a category for a value. It describes what the value represents and how it can be used.
Just a few basic types form the building blocks of all data. We call these primitive data types because we can create all other types of data by composing them. In Python, the primitive data types are integers, floats, booleans, and strings.
Integers
An integer is any number without a decimal point. It includes negative numbers, positive numbers, and zero.
The values 1, 2024, 123456789, 0, -41, and -1000000 are all integers.
! We don't add commas between digits. The computer doesn't recognize the comma-separated -1,000,000 as an integer.
Floats
A float is any number with a decimal point. The name float comes from the term floating point number because the decimal point 'floats' between digits.
The values 1.5 , 3.14159 , 56.01 , -91.7, and -33.33333 are all floats.
The values 22.000 , 0.0, and -1.0 are also floats. The computer recognizes any number written with a decimal point as a float, even if its decimal part is zero.
Booleans
A boolean is a truth value. It can only be one of two possible values: True or False.
We can think of a boolean value as indicating the answer to a question with only two options. Yes or no? On or off? Logged in or logged out?
! In Python, the capitalization of True and False matters. The computer does not recognize the lowercase true or false as booleans.
Strings
A string is text, shortened from: a string of characters. A character is any letter, number, symbol, or space that we can type on a keyboard. A string must be surrounded by quotation marks.
The values "z" , "python@example.com" , "Try it out!" , "25% off", and ":)" are all strings.
The values "-12" , "98.5" , "2 + 2" , and "True" are also strings. The computer recognizes anything surrounded by quotation marks as a string, even if the text inside the quotation marks looks like a number or a boolean.
The value "" is a string, often called the empty string because it contains no characters. This is different from the value " ", which contains a single space character.