Python · Stage 0 · Before You Code · Lesson 5 of 50

Your First Python File

Create a Python file and run print("Hello, world!") with every symbol explained.

Open a plain-text code editor such as Visual Studio Code, Windows Notepad, or TextEdit in plain-text mode. Create a new file and save it as hello.py inside Documents.

Type exactly one line into the file:

print("Hello, world!")
Line-by-line explanation
  1. print is a Python instruction that displays a value.
  2. ( opens the place where information is given to print.
  3. " begins the text.
  4. Hello, world! is the text.
  5. The next " ends the text.
  6. ) closes the instruction.

Save the file. Open a terminal, move into Documents, and run it on Windows:

python hello.py
Line-by-line explanation
  1. python starts the Python interpreter.
  2. hello.py tells Python which file to run.
  3. The output should be Hello, world!.

On macOS or Linux, use:

python3 hello.py
Line-by-line explanation
  1. python3 starts Python 3.
  2. hello.py is the file to run.
  3. The output should be Hello, world!.

Tiny Practice: Your Greeting

Change the program so it displays a greeting with your name.

Starter template

print("Hello, world!")
Line-by-line explanation
  1. print displays text.
  2. The text between quotes is the part to change.
Hint
  1. Keep print(.
  2. Keep straight quote marks around the message.
  3. Save before running.
Show Solution
print("Hello, Asha!")
Line-by-line explanation
  1. print asks Python to display something.
  2. "Hello, Asha!" is one piece of text.
  3. The output is Hello, Asha!.