DEV Community

Kajiru
Kajiru

Posted on

Getting Started with Python (Part 2): Running Your First Python Program

Let’s Run Python (Installation Guide)

In this chapter, we’ll go through the steps to set up a Python development environment.

1. Download and Install Python

Download the Python installer from the official website and install it.

https://www.python.org/downloads/

2. Launch IDLE

When you install Python, a dedicated editor called IDLE is installed at the same time.
Let’s launch IDLE using the steps below.

On macOS

Open IDLE from Finder as follows:

Applications → Python 3.xx → IDLE.app

On Windows

Open IDLE from the Start menu:

Start Menu → Search for “Python” → IDLE (Python 3.xx)

3. Display Some Text

Let’s try printing a greeting with Python.
(From here on, screenshots are shown on macOS, but the steps are basically the same on Windows.)

In the IDLE shell window, type the following code and press the Enter key:

print("Hello, Python!!")
Enter fullscreen mode Exit fullscreen mode

If you see Hello, Python!! displayed, it worked!

4. Save a Program to a File

Next, let’s save a program to a file so we can run it anytime.

4-1. Create a New File

From the top menu, create a new file using the following steps:

File → New File

4-2. Enter the Code

A window named “untitled” will open. (At this point, the file has not been saved yet.)
Enter the following code in this window:

print("Hello, IDLE!!")
Enter fullscreen mode Exit fullscreen mode

4-3. Save the File

Save the file using the steps below.
Name the file main.py.

(You can choose any location, but keeping your files organized in one folder is recommended.)

File → Save

4-4. Run the Program

Run the program from the top menu as follows:

Run → Run Module

If Hello, IDLE!! appears in the shell window, the program ran successfully.

You will repeat these steps as you continue writing Python code.

5. Open an Existing File

To open a program that you previously saved, follow these steps:

File → Open

Select the main.py file you saved earlier, and the code will be displayed.

Coming Up Next...

Thank you very much for reading!
The next chapter is titled “Let’s Do Some Calculations”.
Stay tuned!

Top comments (0)