Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

Variables & Numbers · Lesson 8 of 11

Numbers (int & float)

A free lesson from Swipe Coding · Python, level 2 · updated October 2026

By the Swipe team, founded by Colin · how we make lessons

🤖
Two number types, zero type keywords to write — Python figures it out from the value itself. 🐍

Python has two main number types you'll use constantly: int for whole numbers (no decimal point) and float for numbers with a decimal point. You never declare which one a variable is — Python decides based on how you write the value.

quantity = 10        # int
price = 4.99         # float
total = 3.0          # a float, even though it has no fractional part
print(type(quantity))  # <class 'int'>
print(type(price))     # <class 'float'>
Writing a decimal point, even .0, is what makes a number a float instead of an int. The built-in type() function reports a value's class so you can check.

The usual arithmetic operators work as expected: + for addition, - for subtraction, * for multiplication, and / for division. Mixing an int and a float in the same calculation always produces a float, since Python automatically widens the int so no precision is lost.

result = 10 + 3.5
print(result)        # 13.5
print(type(result))  # <class 'float'>
Adding an int and a float gives a float result — Python promotes the int automatically.
🤖
Three division-flavored operators, three very different results — easy to mix up at first. ➗

There are two special division operators worth knowing: / always produces a float (called true division), even when dividing two ints evenly, while // performs floor division, dropping any remainder to give a whole-number result. The % operator gives you the remainder of a division, which is useful for checking things like whether a number is even.

print(7 / 2)   # 3.5
print(7 // 2)  # 3
print(7 % 2)   # 1
/ always gives a float, // rounds down to the nearest whole number, and % gives the remainder.
Fill in the blank

The built-in ____ function lets you check what type a value currently is, such as int or float.

Quick check

What is the result of 10 + 3.5 in Python, and what type is it?

True or false

Writing total = 3.0 creates a float, even though the value has no fractional part.

Chapter quiz

Variables & Numbers

10 questions · pass with 60% — just like in the app.

Quick check

What must you write before a variable name when creating it in Python?

True or false

Python is dynamically typed, meaning a variable can be reassigned to a value of a different type.

Fill in the blank

Python's naming convention for variables is ____, e.g. total_score.

Quick check

Which line creates two variables, a and b, in a single line?

True or false

Variable names in Python are case-sensitive, so score and Score are different variables.

Fill in the blank

The ____ type stores whole numbers with no decimal point.

Quick check

What type is the value 3.0 in Python?

True or false

Adding an int and a float together, like 10 + 3.5, always produces a float.

Fill in the blank

The built-in ____ function lets you check what type a value currently is.

Quick check

What does 7 // 2 evaluate to in Python?

Keep your streak going in Swipe Coding

Swipe through every level of Python on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.

Get the Swipe apps →