✦ Python Foundations Second lesson

Concept 02 · Data Types

Data Types —
What Kind of Value Is This?

Python values can look similar but behave differently. Learn how numbers, text, and true/false values shape what your code does.

01 Learn02 Try03 Predict

Learning as a guest

Learning as a guest? Save your progress!

Create a free account to learn with Sloby AI, check your understanding, and track your progress.

The entire platform is free throughout 2026. Foundations stays free forever.

A value has content and a type.

In the Variables lesson, you wrote age = 25: age is the name and 25 is the value. Now add one important idea: the value 25 has the type int. A useful mental model is value → type → behavior. The type helps Python decide how it can use and interpret a value.

age = 25        # value: 25, type: int
text_age = "25" # value: "25", type: str

These values look similar because both contain 2 and 5. But 25 is a number and "25" is text. Data types are not just labels to memorize: they affect what Python does with values.

25 → int → behaves like a number "25" → str → behaves like text

Think back to age = 25: age is the variable name, 25 is the value, and int is the value’s type. We are building on Variables, not starting over.

↳

Why types matter: Python needs to know whether a value is a number, text, or a true/false state so it can handle the value in a useful way.

int: whole numbers
age = 25
temperature = -4
score = 0
year = 2026

An int represents a whole number with no decimal part. It can be positive, negative, or zero. Ages, scores, years, and temperatures can all be integers when they have no decimal part.

float: numbers with a decimal part
price = 19.5
height = 1.82
temperature = -3.5

A float is a number with a decimal part. In Python, write the decimal separator with a dot: 19.5, not a comma. Prices, measurements, and some temperatures often need a float.

str: text in quotation marks
name = "Ana"
city = "Novi Sad"
message = 'Hello'
text_age = "25"

A str, short for string, represents text. Write simple strings inside single or double quotation marks. A string can contain letters, digits, spaces, and other characters — so "25" is text even though it looks like a number.

bool: a value with two possible states
is_ready = True
is_logged_in = False
has_permission = True

A bool, short for Boolean, represents a two-state idea such as yes/no, on/off, or ready/not ready. Python’s Boolean values are exactly True and False: no quotation marks and a capital first letter. True is a Boolean; "True" is a string. Later, Boolean values will help programs make decisions.

Ask Python with type()
age = 25
print(type(age))

# <class 'int'>

print(type(25))
print(type("25"))
print(type(19.5))
print(type(True))

Use type() to ask Python what type a value currently has. For now, read <class 'int'> as “Python says this value has type int.” We will learn later why Python uses the word class. The important part now is what type() checks, not memorizing this output format.

The central experiment: 25 versus "25"
number = 25
text = "25"

print(type(number))
print(type(text))

Quotation marks change how Python interprets the value. 25 has type int; "25" has type str. Values can look similar to us and still have different types in Python.

One operator, two behaviors
print(2 + 3)
print("2" + "3")

The first line prints 5 because + adds two numbers. The second line prints 23 because + joins two strings. The same + symbol behaves differently because the values have different types.

Choose the type that matches the information
name = "Ana"
age = 12
height = 1.55
is_student = True

name is a str, age is an int, height is a float, and is_student is a bool. Ask yourself: why would "12" usually be a worse choice for age if a program plans to calculate with it?

A name can later refer to another type
value = 10
print(type(value))

value = "ten"
print(type(value))

Python allows the same variable name to later receive a value with a different type. The type belongs to the value currently assigned to the name. You may later hear this called dynamic typing, but you do not need that term yet. Clear, consistent variable names still make programs easier to understand.

Common beginner mistakes
age = "25"          # text, not a number
is_ready = "True"    # text, not a Boolean
price = 19.5         # use a dot for decimals

None of these lines is necessarily a syntax error. But valid Python is not always the right way to represent the information. If you want to calculate with age, use 25, not "25". If you want a true/false state, use True, not "True".

Read the code before you run it
product = "Notebook"
quantity = 3
price = 4.5
in_stock = True

Pause and identify each value: Which one is a string? Which is an integer, a float, and a Boolean? What do you expect type(quantity) to report? Learning to recognize types while reading code is just as useful as running it.

Python Playground

Loading Python runtime…

Run the starting code and read the type of every value. Then change age = 25 to age = "25" and run it again. Add or remove quotation marks around one value at a time, try is_ready = "True", and observe the difference. Finally, return the code to a valid, meaningful state. Do not convert values yet — this experiment is about seeing how quotation marks affect their types.

data_types.pyPython
OutputWaiting for Python
The browser runtime is loading. You can still edit the example code.

Pyodide runs Python in a browser Web Worker. It is stopped and restarted if code keeps running. Browser execution is not a complete security boundary; do not enter secrets or rely on it for untrusted code isolation.

What will this program print?

Look closely at the quotation marks before you predict the result.

x = "5"
y = "3"

print(x + y)
Choose the output
Sloby, the Python AI Tutor mascot

Your learning mentor

Sign in to ask Sloby

Create a free account or sign in to get AI guidance while you learn.

Sign in to check your understanding

Create a free account or sign in to receive AI feedback and save your learning progress.

Python AI Tutor · Learn by understanding, not just by running code.