Python Values and Types: int, float, and str

Python 3.14 · ✓ verified by execution on 2026-07-19

Every piece of data in Python is a value, and every value has a type — a kind. Knowing the type tells you what you can do with the value. Three types cover almost everything you’ll use at first. Run this and change the values:

python
print(42)
print(3.14)
print("hello")
Output
42
3.14
hello

Those are the three you’ll meet constantly:

Ask Python the type with type()

You don’t have to guess a value’s type — the built-in type() function tells you. Edit the value inside type(...) and run it to inspect anything you like:

python
print(type(42))
Output
<class 'int'>
python
print(type(3.14))
Output
<class 'float'>
python
print(type("hello"))
Output
<class 'str'>

Read <class 'int'> as simply “this is an int.” type() only reports the type — it never changes the value.

The division surprise

Here’s the one that trips up almost every beginner. What is 10 / 2? You’d say 5 — and you’re right about the number, but not the type:

python
print(10 / 2)
Output
5.0

It’s 5.0, not 5. The division operator / always gives back a float, even when the numbers divide evenly. Prove it:

python
print(type(10 / 2))
Output
<class 'float'>

Keep this in mind — a value that looks like a whole number can still be a float.

Quotes decide: “42” is not 42

Putting digits in quotes makes them text, not a number:

python
print(type("42"))
Output
<class 'str'>

"42" is a str; 42 is an int. They look similar but they are different types — and Python treats them very differently. Because of that, you can’t just add text to a number:

python
print("5" + 5)
This example raises an error (on purpose)
TypeError

Python raises a TypeError: it won’t guess whether you meant to join text ("55") or add numbers (10). You have to be explicit — which is exactly what the next lessons build toward.

Edge cases worth remembering

Check yourself

What does 10 / 2 evaluate to in Python?

Reveal answer

5.0 — a float — The / operator always returns a float, so 10 / 2 is 5.0 even though 10 divides evenly by 2. Its type is float.

Are "42" and 42 the same thing in Python?

Reveal answer

No — "42" is a str (text) and 42 is an int (a number) — Quotes make a value a string. "42" is text; 42 is a number. They are different types and behave differently.

What does type() do?

Reveal answer

Reports what type a value already is — type() only inspects — it tells you the type of a value and never changes the value itself.

What happens when you run print("5" + 5)?

Reveal answer

Python raises a TypeError — "5" is a string and 5 is an int. Python won't guess whether you meant to join text or add numbers, so it raises TypeError.

Challenges

Challenge 1 +10 XP

Print the type of the whole number 100.

python
  • Test 1 — expects "<class 'int'>"
Need a hint? (−25% XP)

Wrap 100 in type(), then wrap that in print().

Show solution (0 XP)
print(type(100))

Challenge 2 +15 XP

On the first line print the result of 5 divided by 2. On the second line print the type of that result.

python
  • Test 1 — expects "2.5\n<class 'float'>"
Need a hint? (−25% XP)

5 / 2 is 2.5 — and remember what type division always produces.

Show solution (0 XP)
print(5 / 2)
print(type(5 / 2))