Legends ofPythos
Claim your name
Python Basics

Your first program

Lesson 1 of 13

Watch the lesson0:57 ยท with Sigrid
A program is a list of instructions for your computer to follow step by step. In Python, these steps look like plain English sentences. You write them in a text file and ask the computer to read that file from top to bottom.

Your first command

Your first tool is print(). It is a function, which means it does one specific job: showing text on the screen. You give it what to show inside parentheses.
print('Hello, world!')
Printing your first message
This line tells Python to display the exact text Hello, world!. The quotes tell Python that this is a string, or words meant for reading. If you remove the quotes, Python thinks it is looking for a variable name and will crash.

Creating multiple lines

Python runs your code one line at a time. Each print() call ends with an automatic newline. This means the next thing you print appears on the very next line of text.
print('My name is')
print('Alex')
Printing two separate lines
Here, the first line prints My name is. The second line starts fresh below it. You do not need special characters to move down; Python handles that for you automatically.

Adding notes with comments

Code is often read by humans before it runs. You can leave notes using the # symbol to start a comment. Python ignores everything after #, so you can write English sentences there safely.
# This line does nothing
print('I am real code')
# print('This is skipped')
Using comments to explain or disable code
Comments help you remember why a line exists. They also let you temporarily turn off code while testing other parts of your program.

Your turn

0 of 2 solved

Exercise 1

+20 XP
Write a program that prints the text Hello, world! exactly once.
Write your Python here.

Run your code to check it against the tests.

Exercise 2

+20 XP
Write a program that prints two lines. The first line should be My name is. The second line should be your age as a whole number (any whole number is fine). You can start with a comment saying what the program does: Python ignores comments, so it won't change what gets printed.
Write your Python here.

Run your code to check it against the tests.