Challenge 1-5: Booleans - True and False

Types of Data

We've learned about three types of data so far:

27 integers (whole numbers)

15.238 floats (decimal points)

"Hi!" strings (characters between quotes)

Python can tell us about types using a function called type() .

Let's stop for a minute here and talk about this new word, function. In programming, a function is a command that performs a specific task.

Later on, we'll take what we've learned about Python and write some of our own functions. But for now, you need to know that Python has a lot of functions that are built in - that is, they are already included, so you don't have to do anything special to use them.

We've already used a few of Python's functions - we've seen print() , and we used round() when we talked about maths.

To call the type() function, simply type the word 'type', then any kind of data inside the parentheses.

In this example, we're using our string, "Hi!" It should look just like this when you type it into the Python Shell:


>>> type("Hi!")

And when you hit Enter, you should see this:


<class 'str'>

We called the function type() and what Python returned to us was a message that tells us our type was str , which is short for 'string'.

What happens when you ask for the type of an integer or a flat? Let's try those out.

>>> type(27)

>>> type(15.238)

Did you get <class 'int'> and <class 'float'>?