In this course you'll learn to talk to computers using Python — one of the most popular coding languages in the world! We'll use fun examples with animals, games, food, and stories. Every lesson has code you can run and change yourself right here on this page.
- Use
print()to display messages on screen - Understand what a variable is and how to create one
- Work with text (called strings) and numbers
- Combine text and variables together
- Ask questions with
input()and use the answers
print() tells Python to show something on the screen. Whatever you put inside the parentheses gets displayed. Text goes inside quotes: print("Hello!"). Python runs your program from the top line to the bottom, one line at a time. Lines that start with # are comments: notes for people, Python skips them.- Change
"Hello, World!"so it says hello to your best friend, then press ▶ Run. - Add a new line at the bottom:
print("My favorite color is blue"), with your own color. - Delete one of the quote marks
"and Run. Meet your first error message! The 🐞 box further down explains it. Put the quote back.
my_age = 10 means "put 10 in the box called my_age". Names use small letters and underscores, no spaces: my_pet, not my pet. Change my_name to your actual name!- Put in your own name, age and pet, and Run.
- In the last line, change
my_age + 5tomy_age + 10. How old will you be? - Add a new variable
my_city = "Boston"(your own city) and a line that prints it.
"penguin". Numbers have no quotes: 10. You can glue strings together with +, but not a string and a number: turn the number into text first with str(my_age). The easiest way is an f-string: put an f before the quote and the variable in curly brackets, like f"I am {my_age} years old".- Change
"penguin"to your favorite animal. Does the letter count change? - Make it laugh 100 times:
print("Ha" * 100). - Try
print(animal.lower())andprint(animal.title()). What do they do?
input("What is your name? ") shows the question, waits for you to type an answer, and gives the answer back so you can keep it in a variable: name = input("What is your name? "). When you press ▶ Run, a small box pops up for each question. What you type is always text, even a number: you will learn how to do math with it in lesson 2.- Run it and give silly answers. Python believes everything!
- Add a third question:
pet = input("What pet would you like? "), and a line that prints it. - Make Python repeat your food three times with
food * 3.
- SyntaxError: unterminated string literal
- A quote mark is missing. Every piece of text needs a quote at the start and at the end:
"hello". - NameError: name 'my_nme' is not defined
- Python does not know that name, usually because of a spelling mistake. Names must match exactly, capital letters too.
- TypeError: can only concatenate str (not "int") to str
- You glued text and a number with
+. Usestr(my_age), or an f-string:f"I am {my_age}".
print()shows things on the screen, top line first.- A variable is a named box:
my_age = 10. - Text needs quotes and is called a string. Join strings with
+, or use an f-string. .upper()andlen()change and measure strings.input()asks a question and gives back the answer as text.
New words: comment, variable, string, f-string, input, error message
Each challenge has its own code box: change the code, press ▶ Run to see it work, then ✓ Check. When the four numbered challenges pass, the lesson is done. The warm-up and the ⭐ star challenge are extras: try the warm-up first if you like, and the star when you want something harder.
Warm-up What does this print? Count carefully!
Challenge Introduce yourself. Change my_name, my_age and my_pet to your own, and keep every sentence working.
Challenge Add a new variable my_favorite_food and print a sentence that uses it.
Challenge Read the code and predict the two lines it prints. Think about what .upper() and len() do.
Challenge This program has a bug: Python can't glue text and a number together. Fix it so it prints I am 9 years old.
⭐ Star challenge Robot greeter 🤖: ask for a name with input(), then greet in capitals. If the answer is Mia, it prints HELLO, MIA!
You finished Beginner Python
Keep going with Intermediate Python and Python4Physics: twelve lessons, $29 a month, start with either, each lesson opening as you finish the one before, at your own pace.
Subscribe, $29 a month Full curriculum