Python course / Foundations
Values and variables
Write your first working programs: show a value, store one under a name, and move between text and numbers. Most early bugs are a number that is secretly text, and this is where you learn to tell them apart.
- printing
- strings
- numbers
- variables
- types
- f-strings
- slicing
- input()
Runs in your browser. Start straight away; create an account when you want your progress kept.
price = "3.50"
count = 4
total = float(price) * count
label = "tea"
print(f"{count} x {label}: {total:.2f}")
print(label.upper(), label[0], label[1:])
4 x tea: 14.00 TEA t ea
What you will learn
- Make the program say something.
- Use Python as a calculator.
- Store a value under a name and reuse it.
- Turn text into numbers and back.
- Build readable text from values.
- Take a section out of a string.
The lessons in this module
- Printing output
- Text values
- Numbers and arithmetic
- Variables
- Changing a variable
- Types
- Converting between types
- f-strings
- String methods
- Reaching into a string
- Slicing
- Reading input
- Comments and layout
- Module review: unit converter
Ready when you are
Next: Conditions and branching. All modules are on the course page.