📚

Type Inspection

Finding Out a Variable's Type

Every value in Python has a type — it determines what you can do with that value. You can't multiply text! Python needs to know if something is a number, text, or something else.

The

type()
function tells you what type a value is:

x = 42
y = 3.14
z = "hello"

print(type(x))    # → <class 'int'>
print(type(y))    # → <class 'float'>
print(type(z))    # → <class 'str'>

Here's what each type means:

TypeWhat it isExamples
int
Whole numbers
42
,
-7
,
0
float
Decimal numbers
3.14
,
-0.5
,
1.0
str
Text (strings)
"hello"
,
'world'
bool
True or False
True
,
False

Why Does Type Matter?

Because types determine what operations are allowed:

print(5 + 3)         # → 8  (number + number = math)
print("Hello" + "!")  # → Hello!  (text + text = join)
print("Hello" + 5)   # ❌ ERROR! Can't add text and number
💡

💡 Debugging tip: If your code crashes unexpectedly, check the types of your variables with

type()
. The problem is often a type mismatch!

main.pySandbox
main.py