Lesson 3 of 34

Data Types: Numbers, Text and True/False

8 min 20 XP

Every value in Python has a type: whole numbers are int, decimals are float, text is str, and True/False is bool. type() tells you the type.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

Careful: "10" is text (a string), while 10 is a number. Adding two strings joins them. To calculate, convert them to numbers with int().

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

int("5") → 5, float("2.5") → 2.5, str(10) → "10". This is called type conversion.

Challenge

+20 XP

price = "250" is a string and qty = 3. Calculate and print the total (price × qty). The correct answer is 750.

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.