Beginner level · Module 1: Python Setup and First Programs · Lesson 2 of 3
Variables, Data Types and Input/Output
Store values in variables, recognise the basic data types and build readable output with f-strings.
In this lesson you will
- Choose suitable variable names and types
- Combine values into formatted output with f-strings
Key concepts
variablestr/int/float/booltype()f-string
The lesson
A variable is a name that refers to a value, such as price = 2500. Python works out the type from the value: whole numbers are int, decimals are float, text is str and True/False is bool. You can check any value's type with type().
input() always returns text, even when the user types digits. To calculate with it you must convert it: int(input(...)) or float(input(...)). Forgetting this is the most common beginner error — '2500' + '300' gives '2500300', not 2800.
f-strings are the modern way to build output. Put f before the quotes and place variables inside curly braces: f"{name}: {total:,} SSP". The :, format adds thousands separators, which makes money easier to read.
Step by step
- Create name, price and quantity variables and print their types.
- Ask the user for a quantity with input() and convert it with int().
- Multiply price by quantity and store the result in total.
- Print a receipt line with an f-string and a thousands separator.
Practice activity
Write a script that asks for a customer's name and the price of two items in SSP, then prints a receipt line with the total.
Expected result: Your script prints a receipt line such as 'Grace: 12,500 SSP' from what you typed.
Check your understanding
-
What type does input() return?
Show answer
Always a string (str), even if the user types a number.
-
How would you print 1234567 as 1,234,567 using an f-string?
Show answer
f'{1234567:,}'
Further learning
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.