Floats

Here we're learning something new about how Python works with numbers.

In Python, and in many other programming languages, a decimal number is called a float.

Here are some examples of decimal numbers, or floats:

10.0
17.31
2.5346

When we type a math expression using division, Python gives a float back to us as a response - the answer will always be some sort of decimal number. Python uses floats by default because it wants to give us the most accurate answer possible.

>>> 10 / 3

3.333333333333335

>>> 10 / 5

2.0

And below you can see some examples of integers - or whole numbers:

9
-55
346

If we want Python to give us an integer instead of a float, we have to use this built-in Python function, called round(). Type the word round , then inside parentheses type one of the division expressions and hit the Enter key.

>>> round(10/3)

3

>>> round(10/5)

2

Go ahead and try a few more expressions using different numbers. You might notice some new things.

The rule we've learned here is that if you want Python answers with floats - if you want to get integers, you have to use the built-in function round() .

Before we move on to the next thing, let's take a minute to talk about some new words you'll hear more of soon.

When we say that Python returns something, we're talking about the answers that Python gives us. When you type something at the prompt and hit Enter, you're asking Python a question. Then Python gives back, or returns, an answer to you.

We've also been using this word expression - you'll hear that a lot more as we go on. So far the expressions we've seen have been math problems. But expressions can be a lot more - we're also going to see some expressions that use words and other kinds of symbols.