Course curriculum
Variables and data types
Store values, distinguish numbers from strings and use clear names for changing information.
About 9 minutes · BeginnerName a value
Assignment binds a name to a value. Use names that describe the meaning of the value, such as completed_units, instead of vague names such as x.
Python distinguishes integers, floating-point numbers, strings and booleans. The same name can later refer to another value, but predictable types make your code easier to understand.
completed_units = 3
total_units = 8
remaining_units = total_units - completed_units
print(remaining_units)5
Text and numbers are different
The string "12" contains characters; the integer 12 is a number. Adding two strings joins them. Convert a numeric string with int when you need arithmetic.
Conversion can fail: int("twelve") raises ValueError. Validate external input before assuming it contains a number.
pages = int("12")
print(pages + 3)
print("12" + "3")15 123
Format readable output
An f-string inserts expressions between braces. It lets you combine labels and values without manually converting every number.
Use == to compare values. A single = assigns a value and is not a comparison.
subject = "Physics"
score = 42
print(f"{subject}: {score} marks")Physics: 42 marks
Try it yourself
Store a price of 50 and a quantity of 4. Calculate the total and print “Total: 200”.
Show a possible solution
price = 50
quantity = 4
total = price * quantity
print(f"Total: {total}")Keep exploring: official Python documentation.