Numbers and Text Values

Introduction

Welcome back to Writing and Running Your First Python Programs! We have reached the third lesson of this course, so we are ready to build on what we have learned.

In the first two lessons, we learned to display output with print() and to keep our programs readable using comments and thoughtful spacing. Along the way, we printed both text and numbers, but we never really paused to ask: what kind of value are we actually printing?

That is our focus today. Every value in Python has a type, which is a label that tells Python what kind of data it is. In this lesson, we will meet the three types beginners see first: integers, floating-point numbers, and strings. We will also pick up a handy built-in tool called type() that reveals which type any value belongs to.

Values Have Types

Before we look at any code, let's build a little intuition. Think of a type as a category. In everyday life, the number 7, the number 3.5, and the word "hello" feel like different kinds of things: two of them are numbers, one is text, and even the two numbers behave differently because one has a decimal point.

Python thinks about values the same way. Each value belongs to a category, and that category decides what Python can do with it. Adding two numbers works smoothly, but combining a number and a piece of text takes extra care, because they are simply different kinds of data.

Knowing the type of each value helps us avoid surprises and write programs that behave the way we expect.

Integers and the type() Function

Let's start with the simplest kind of number: the integer. An integer is a whole number with no decimal point, positive or negative, such as 7, 0, or -42. Printing one looks exactly like what we already know from the first lesson:

# An integer (whole number)
print(7)

That gives us:

7

Nothing surprising there. But how does Python actually label this value? For that, we can use the built-in type() function. When we wrap a value in type(), it hands back the value's type, and we can nest that call inside print() to display the result:

print(type(7))

Output:

<class 'int'>

The line <class 'int'> is Python's way of saying, "this value belongs to the int class," which is the technical name for the integer type. Every whole number we write will report the same type.

Floating-Point Numbers

Numbers with a decimal point are called floating-point numbers, or floats for short. The name comes from the fact that the decimal point can "float" to different positions, letting the same type represent values like 3.5, 0.001, or 12.75.

# A floating-point number (has a decimal point)
print(3.5)
print(type(3.5))

Running these two lines produces:

3.5
<class 'float'>

A couple of things to notice:

  • The first line prints 3.5 just as we wrote it, decimal point and all.
  • The second line reveals its type: <class 'float'>, meaning the value belongs to the float class.

Compare this with 7 from the previous section. The only visible difference is the decimal point; yet, Python treats them as entirely different types: 7 is an int, while 3.5 is a float. Even 7.0, though it equals seven, would be a float because of that decimal point.

Strings: Text Inside Quotes

The third type we will meet is the string, which is Python's name for text. We have actually been printing strings since our very first lesson; every time we wrote something inside quotes, that was a string. Now we finally get to name it.

# A string (text inside quotes)
print("hello")
print(type("hello"))

The output is:

hello
<class 'str'>

Notice how hello prints without the surrounding quotes; those quotes are not part of the text itself — they are just a signal to Python that we mean text, not code. The second line confirms the type: <class 'str'>, where str is short for string.

Without the quotes, Python would try to interpret hello as the name of something in our program and would raise an error because no such name exists. The quotes are what turn those five letters into a string value.

The Three Types at a Glance

Here is a quick summary of the three types we met, side by side:

Example valueTypeWhat it is
7inta whole number
3.5floata number with a decimal point
"hello"strtext inside quotes

Keeping this little table in mind makes it easy to guess what type() will report before you even run your code.

Conclusion and Next Steps

Nicely done! We have now met the three most common value types in Python: integers (int) for whole numbers, floating-point numbers (float) for numbers with a decimal point, and strings (str) for text inside quotes. We also picked up a new tool, type(), that reveals the type of any value we hand it.

And with that, we are ready for the next lesson in Writing and Running Your First Python Programs! In that lesson, we will use number values in arithmetic expressions so Python can work out results for us. But first, a short set of hands-on exercises is waiting to help us lock in what we just learned. Let's jump in and put these new types to work!

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal