About 5 minutes
Your first program
One line of Python that shows a message on the screen. By the end of this page you'll write it yourself and know what every piece does.
1. print, piece by piece
Here's the whole program. Just one line:
print("Namaste")It has three pieces:
printThe command. It shows something on the screen.( )Round brackets. They hold what you want to show."Namaste"Your message, in double quotes. Quotes tell Python: this is text.When it runs, Namaste appears on the screen, exactly as you typed it.
TRY IT: CHANGE THE MESSAGE, THEN RUN
OUTPUT
Press Run
2. Top to bottom
With more than one line, Python starts at the top and runs one line at a time, in order. Always.
print("Namaste")
print("Welcome to Tryline")OUTPUT
Namaste Welcome to Tryline
In what order does Python run these lines?
3. More than one thing
print can show several things at once. Separate them with commas. You get all of them with a space in between, and the commas don't show.
print("Latte", "Muffin", "Cake")OUTPUT
Latte Muffin Cake
4. Two mistakes everyone makes
Make them once here, so they never scare you later.
Forgetting the quotes
print(Namaste)
NameError: name 'Namaste' is not defined
Without quotes, Python thinks Namaste is a name it should know, not text. Add the quotes back.Curly quotes from a phone
print(“Namaste”)
SyntaxError: invalid character '“' (U+201C)
Phones and Word make slanted quotes. Python only accepts the straight ones from your keyboard. Retype them.You wrote print(Hello) and got a NameError. What's missing?
5. Where it's used
Every program uses print to show results: a bill, a welcome screen, an app's message. Developers also use it all day to check what their code is doing.
Shop welcome screensBills and receiptsChecking your own code
Ready for your missionKettle & Crumb: "Our welcome screen is blank!"
Start the missionWas this page clear?