How to Write Your First Python Program
A Python program is simply a text file. To write your first Python program, you need a text editor.
We recommend downloading the Sublime editor. It is free to use. Occasionally, a message may appear asking for payment, but you can ignore this at the beginner stage.
After installation, launch Sublime and type the simplest Python program for beginners in the opened window:
print("Hello, world!")
Here, print is a function that displays the text enclosed in parentheses on the screen. You must close the parenthesis and use quotation marks, or your program will have an error and the interpreter won’t execute it.
Save the text file as hello.py.
To see how the program works, open the terminal (command line) application. On Windows, press the Win+R keys and type cmd in the “Run” window. On MacOS, press Command+Space and type Terminal in the spotlight window.
In the terminal window, navigate to the directory where the hello.py file is saved. Use the cd command to go to the desired directory. Enter the following in the terminal prompt and press Enter:
cd path/to/folder/with/program
If you are using Windows and the program is saved at the root of a drive, such as drive D, type the drive name followed by a colon and press Enter:
D:
To run the program, type the following in the terminal:
python3 hello.py
if you are using MacOS, or
python hello.py
if you are using Windows. Press Enter.
If everything is correct, the screen will display the message:
Hello, world!
Congratulations! You’ve written your first program!