✦ 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

A data type tells Python what kind of value it is using.

A value can be a whole number, a decimal number, text, or a true/false value. Python uses its data type to decide how that value behaves.

age = 25             # int
price = 19.5         # float
name = "Sloby"       # str
is_ready = True      # bool

int is a whole number, float has a decimal part, str is text, and bool is either True or False.

type(age) # <class 'int'>

The type belongs to the value. A variable can later refer to a value with a different type.

↳

Quotation marks matter: Writing 25 creates a number. Writing "25" creates text, even though the characters look the same.

Same characters, different types
age = 25
text_age = "25"

age is a number, while text_age is text because it has quotation marks.

Check a value with type()
print(type(25))
print(type("25"))

The type() function lets you ask Python what kind of value it sees.

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

With numbers, + adds. With two strings, + joins text together.

Python Playground

Loading Python runtime…

Change the values and run the code. What happens when you add or remove quotation marks?

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

Ask Sloby about data types

Describe what feels unclear. Sloby will help you compare numbers, strings, and booleans.

Hi! I'm Sloby. Ask me anything about Python data types. We can explore numbers, strings, and booleans together!

What will this program print, and why are the results different?

a = 10
b = "10"

print(a + a)
print(b + b)
Python AI Tutor · Learn by understanding, not just by running code.