Lesson · Python for Beginners
Set up Python and run your first program
A working setup makes it possible to test ideas instead of guessing what code will do.
What you will learn
- Check that Python 3 is available
- Run a saved script
- Recognize the difference between code and output
Check the interpreter
Python is both a language and a program that reads instructions written in that language. Install a current Python 3 release from the official Python website, and enable the installer option that adds Python to your command line when it is offered. Open a new terminal after installation so it can find the command.
Save a script
A script is a text file containing instructions. Save the example as hello.py, then run it from the directory containing that file with python hello.py; on some systems the command is python3 hello.py. The command starts the interpreter, which reads the file from top to bottom and displays the value passed to print.
Read the result
The line inside the file is an instruction; the word printed beneath the command is output. The prompt and command are supplied by the terminal, not by the Python program. Keeping those roles separate helps when you compare your result with a lesson or diagnose a misspelled command.
Make one safe change
Change the text between the quotation marks and run the script again. Text values need matching opening and closing quotes. If the terminal says it cannot find the file, check the current directory and spelling before reinstalling anything. A small repeatable edit-run-observe cycle is the foundation for later lessons.
print('Hello, Python!')
Expected output
Hello, Python!
Practice exercise
Save a script that prints a greeting containing your first name.
Show a hint
Keep the name inside the quoted text passed to print.
Show one possible solution
For example, print('Hello, Asha!') prints Hello, Asha!. Replace the example name with your own.
Quick check
The terminal command starts the Python interpreter and passes the saved file to it.