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!.