Hello, World!
About 10 minutes
Why this matters
Every program needs a way to show something to a person. In Python, the simplest way is print().
The idea
print() is a function: a named action that Python already knows how to do. You hand it something inside the parentheses, and it shows that something on the screen.
print("Hello, world")
The text between the quotes is called a string. Python prints what is inside the quotes, without the quotes themselves. Single quotes work too: 'Hello' and "Hello" mean the same thing.
Each print() ends by moving to a new line, so two prints show two lines:
print("First line")
print("Second line")
Try it
In the editor below, change the text inside the quotes and press Run. Break something on purpose, too (delete a quote, for example) and read the error message. Errors are not failures; they are Python telling you exactly what it did not understand.
Your turn
The starter program prints Hello, world. Change it so that it prints exactly:
Hello, Python!
Press Run to see your output, then Check to test your answer.
Recap
print()shows something on the screen.- Text in quotes is a string.
- Each
print()call produces its own line.
Common mistakes
- Forgetting the quotes:
print(Hello)fails withNameError, because Python thinksHellois the name of something it should already know. - Missing parenthesis:
print("Hello"fails withSyntaxError. - Wrong capitalisation: Python is case-sensitive.
Print("Hi")fails withNameError.