Module 01 · Lesson 01
Introduction to Python
Meet Python: what a program is, how the interpreter runs your lines from top to bottom, and how to read an error message without panic.
- About 8 minutes
- Beginner friendly
- 12-question quiz at the end
What you will learn
- What Python is
- Your first line
- Think like a computer
- Read an error
Meet Python
A programming language is a way to give a computer instructions. Python is one of the friendliest.
Reads like English
Short, clear lines with few strange symbols. If you can read a sentence, you can start reading Python.
Free for everyone
Anyone can download it. It runs on Windows, macOS, Linux and tiny boards like the Raspberry Pi.
Named after comedy
The name comes from the comedy show Monty Python's Flying Circus, not the snake.
Python is all around you
You have probably used something built with Python today. These programs start from the same print() and names you meet in this lesson.
- AI and chatbotsMost AI models are built and trained with Python. Chat assistants, photo filters and voice helpers all learn from examples fed in by Python code.
- Apps you useInstagram's servers run on a Python web toolkit. Spotify and Netflix use Python behind the scenes to work out what to suggest next.
- Space and scienceIn 2019 scientists used Python to turn telescope data into the first picture of a black hole. NASA teams use it to plan and check missions.
- GamesYou can build your own 2D games with a few hundred lines. The huge space game EVE Online runs much of its logic in Python.
- Data and sportFootball clubs study every pass of a match, and weather services sort millions of readings. Both find the patterns with Python.
- Boring jobs, doneTen lines can rename hundreds of photos in a second. People also use Python to fill in spreadsheets and send reminders for them.
Your first line of Python
This is a whole program. Tap each part to see its job.
Part 1 of 4
command:print is a built-in command. It shows whatever is inside the brackets on the screen. Think of it as a megaphone.
Prints Welcome to Python!
Try your first Python code
Pick an example, change it, then press Run. It runs right here in your browser.
Example 1 of 5Hello
Every coder's first program: make Python say something.
Your turn: Change the second line so it says hello to you by name.
print("Hello, World!")
print("I am learning Python!")Press Run to see what it prints.Think like a computer: the robot game
A computer never guesses. It follows your steps exactly, in order. Build a program to get the robot to the star.
Level 1 of 3Straight ahead
The robot starts top left, facing right.
1. Add moves
2. Your program (0/12)
Tap the moves above to write your program.
Watch Python run, line by line
Press Step to run one line at a time, the way Python does. Watch the names and the output change.
Ready. Press Step to run the first line.
- print("Start")
- score = 5
- score = score + 1
- print("Score:", score)
- print("End")
Output so far
Nothing printed yet.
What Python does
Python reads the program from the top. Nothing has run yet.
Names
None yet.
Draw with code
Python has a drawing pen called `turtle`. It walks forward and turns, and draws as it goes. Pick a shape or slide the numbers.
Shape 1 of 5Square
Real Python opens the turtle in its own window, so here the drawing is a preview of what the code does.
Change the numbers
import turtle t = turtle.Turtle() for i in range(4): t.forward(120) t.right(90)
Challenges0 of 3
- Make a hexagon: 6 sides, and turns that add up to 360 degrees.
- Make an octagon with 8 sides.
- Make a flower with 6 circles.
Why Python feels easier
The same job, printing a greeting, in Python and in other languages.
Language 1 of 2Python vs Java
print("Hello, World!")One line. Almost nothing to memorize before you see a result.
Quick guesses
Guess first, then read why. A wrong guess is where the learning happens. Nothing here is scored.
Question 1 of 6
1.What does this print?
print(7 * 6)0 of 6 answered
Common beginner misconceptions
Worried about any of these? Tap a card.
Misconception 1 of 4
Notes
Everything above, in words. Open it when you want the full explanation.
Read the notesNotesOpenClose
Syntax
The general shape of the statements in this lesson.
print("text") # show text
print(7 + 5) # show the result of a calculation
print("a", "b") # show several values, separated by a space
name = "Ada" # give a value a name
# a comment: Python skips this linePress Run to see what it prints.Worked examples
Read the problem, run the code, then read why it works.
Example 1 of 2
A short program, line by line
Write a program that greets the reader, shows how many minutes are in a day, and then says goodbye. Predict the output before you run it.
print("Hello!")
print("Minutes in a day:")
print(24 * 60)
print("Goodbye.")Press Run to see what it prints.Predict first
How it works(open after your guess)
Common pitfalls
Mistakes people make with this topic, and what to write instead.
Pitfall 1 of 3
Forgetting the quotes around text
Spot the bug
Can you see what is wrong? Run it to watch it go wrong, then open the fix.
print(Hello)
Press Run to see what it prints.Show what goes wrong and the fixWhat goes wrong and the fix
In the real world
Where this shows up in software people use every day.
- Everyday life
Working out a weekly budget
Python is often used for small personal jobs, such as checking how far a weekly budget stretches before you go shopping.
Why Python fits
Each line does one small step, and Python runs them in order. Naming the budget once means you can change it in one place and run the program again for a new answer.
Pythonbudget = 50 spent = 12 + 8 + 15 print("Spent:", spent) print("Left:", budget - spent)OutputPress Run to see what it prints.
Key takeaways
Tick each one you could explain to a friend.
0 of 5
Common questions
Guess the answer first, then open it.
Do I need to install anything?
Is Python slow because it is interpreted?
Do I have to remember all of this?
Your notes
Sign in to keep private notes alongside this lesson.
Where to go next
The quiz and the Lab live on their own pages, so this lesson stays about learning.
Finished this lesson?
Create an ID or sign in to save your progress across devices.
Check what you learned
12 questions, with an explanation after every answer. A verified attempt counts towards opening the module Lab.
Keep going in the Lab
7 tasks on this lesson, from writing code to tracing it by hand. Practice only, no XP.
Spaced review
Questions you miss in a quiz come back on a spaced schedule, so what you learned here sticks.
This lesson at a glance
The 5 lines of code this lesson uses, each with a short note. Keep it open while you do the quiz and the Lab.
What else you can search for and explore
Curious to go further? Each card opens a web search in a new tab.
References
Look things up here whenever you need the exact details.