Learn by doing

Your first script
can be four lines.

Run something small, understand its result and make a change. That is enough to start learning how Python works.

Your first exercise

Calculate something you can check.

This script adds three prices and prints the total. Create a Python file, type the example and press Run.

You should see 30. Change one price and predict the new answer before you run it again.

This example uses standard Python and can be tried on Mac, iPhone or iPad.

my_first_script.py

prices = [12, 8, 10]
total = sum(prices)
print("Your total is:")
print(total)
Your total is:
30

Keep experimenting

One example. Three things to try.

  1. Change a value

    Replace 10 with 20. Predict the total, then run the script to see whether you were right.

  2. Add another price

    Put a fourth number in the list. You have changed the input without rewriting the calculation.

  3. Find the average

    Try average = total / len(prices), then print the average. You are using the same data to answer a new question.

Examples on Mac

Start from code that already does something.

The Mac app includes tutorials for Python basics, arrays, tables and web requests. Open one, run it and use it as a starting point.

Pick the topic closest to what you want to make. It is easier to learn a library when you have a small question for it.

Try a data example next →
Python code and NumPy results in the Mac app
Write your code. Run it. See the result. Mac App Store edition.

Build a learning habit

Give yourself a project small enough to finish.

A tip calculator

Choose a bill amount and a tip percentage. Print the tip and total. Later, add the number of people splitting the bill.

A short quiz

Store a question and answer. Ask for input, compare the response and print feedback. Then add another question.

A reading tracker

Store pages read each day in a list. Add them up and calculate an average. On Mac, try turning the numbers into a chart.

When you get stuck

Look for the smallest next step.

What should I do with an error?

Read the message and the line it points to. Check spelling, brackets and indentation. Try simplifying the script until you can see the cause.

Can I learn on an iPad or iPhone?

Yes. Write and run small scripts in the mobile app. Its guidebook and learning resources can help you explore the language; some features require a subscription.

Should I ask the AI assistant?

It can help explain a line or suggest where to look. Ask for an explanation, then run and check the code yourself so you understand the result.

Make your first script work.

Choose your device and try the four-line exercise above.

Get Python Editor