Free learning guide

Python beginner guide

Start with variables, selection, iteration and small programs.

Begin with print("Hello, world!"), then create a variable such as score = 10. Try changing the value and printing the result. Next, explore if statements and for loops.

Practice

Write a program that asks for a name and prints a greeting. Extension: ask for a number and display its double.

← Browse all resources

Python practice projects

Build your programming skills using our free starter files and reference solutions.

Explore Python resources →

A sensible order for learning Python

Start by displaying text and storing values in variables, then practise input, selection and repetition. Functions make larger programs easier to read and test. In each lesson, predict the output of the example before running it, and then deliberately change one line.

Begin with our 12-lesson Python Foundations course, including downloadable code and a short knowledge check for every topic.

First Python program · free lesson

Python variables, input, selection and loops in one small program

Learning Python is easier when each new idea changes something you can see. Start with a variable, use a whole-number input, add selection and then repeat an action with a loop.

goal = 3
score = int(input("Your score: "))
if score >= goal:
    print("Goal reached")
else:
    print("Keep practising")
for attempt in range(1, 4):
    print("Try", attempt)

The int() call converts valid numerical text into an integer; it will raise an error for input such as three. The loop displays Try 1, Try 2, Try 3.

Mini challenge: make it more robust

Use try/except ValueError to handle an invalid score, then test 0, 3, 4 and non-numeric text. Your program should not crash just because a beginner enters an unexpected value.

Next: the complete beginner Python course, debugging practice, and additional coding exercises.

Keep learning

Related TutorSyntax activities

Continue with a practical task that builds directly on this topic.