Python Foundations · Lesson 1 of 12

Getting started with Python

print(), comments and running a script. Learn through short examples, practical tasks and targeted questions.

← All lessons

Printing messages and comments

The print() function sends information to the console, which is useful for giving feedback and checking that a program reaches a particular line. A comment starts with # and is ignored when the program runs. Try changing the quoted message, then add a second print statement to see the output appear on separate lines.

Watch out: A frequent beginner mistake is to forget quotation marks around text. Python treats unquoted words as names of variables, not messages.

1 · Understand

print(), comments and running a script. Study the code and predict what it does before running it. Change a value or string and observe how the output changes.

print("Welcome to TutorSyntax!")
# Change this message to introduce yourself.
Download example .py ↓

2 · Practise

Write a program that prints three lines: your favourite subject, one reason to learn Python and a goal for the year.

Plan your inputs, processing and outputs. Write the code in Mu, IDLE or PyCharm; test at least three cases.

Show a reference solution after attempting the task
print("Welcome")
print("I am learning Python")
print("My goal is to build a game")
Download reference solution .py ↓

3 · Debug the code

Identify the problem and explain how to fix it before revealing the answer.

print "Hello"
Reveal the corrected program and explanation
print("Hello")

Compare the two snippets. Identify the changed line, run the corrected version and explain the effect.

4 · Check your understanding

Which function displays text?

5 · Challenge and reflect

Extension: Improve your solution to deal with unexpected input, add a second feature or display results more clearly.

Reflect: What was the hardest part? What would you test if someone else used your program?

Want extra practice? Try interactive Python tracing and debugging questions →