← Interacting with Python | Variables →
Types are classifications that let the computer know how a programmer intends to use a piece of data. You can just think of them as, well, types of data.
We've already seen one type in the last section: the integer. In this section, we'll learn four more: the floating point number, the string, the boolean, and the list.
Enter these lines as you see them below:
>>> type(1)
<class 'int'>
>>> type(1.0)
<class 'float'>
>>> type("Hello there!")
<class 'str'>
>>> type(True)
<class 'bool'>
>>> type([1, 2, 3])
<class 'list'>
Each of the responses show how the different types of data registers as different "types" for Python:
Integers (like 1
above) are whole numbers.
Floats (like 1.0
above) are numbers with decimals, and are treated a little differently than integers.
Strings (like "Hello there!"
above) are arbitrary sets of characters, such as letters and numbers. You can think of them as a way to store text.
Booleans: (like True
above) is a fancy term for values representing "true" and "false," or "truthiness" and "falsiness." In Python they are always capitalized: True
and False
.
Lists: (like [1, 2, 3]
above) are ordered collections of values. You can put any of the other types in a list: ["hello", "goodbye", "see ya later"]
is also a valid list.
Don't worry about trying to actively remember these types. We'll be working with each in turn in the following sections.
type()
is a function. You can think of functions in Python in a few different ways:
- A way of doing something in Python.
- A way of saving some code for reuse.
- A way of taking an input, transforming that input, and returning an output. The input goes in the parentheses
()
.
These are all valid ways of thinking about functions. We'll be learning more about functions in later sections.
Open your web browser, and google the phrase "python function." Skim through the first few results. What words do you recognize, and which ones look unfamiliar? What do you think the unfamiliar ones mean? Try to rephrase some of this new language, and guess what they mean in your own words.
When you google "python function," you may see some phrases that look unfamiliar, like "return value" or "pass parameters." These are advanced terms for inputting and outputting data from a function. It's important to become familiar with the Python's terminology about functions, as it will be helpful later on when you start working with these components.
Select all the following that accurately describe the data type categories.
- Booleans represent only
True
orFalse
values.* - Integers can be expressed with numbers like
1
or lettersone
. - Strings can contain numbers within quotations, like
"1"
.* - Lists can contain strings, like
['banana, 'coffee', 'eggs']
.*
Do you remember the glossary terms from this section?