How to run Python Program?

After writing Python code, you need to run it to execute and obtain the output. Running a Python program helps verify that your code is correct and produces the desired results.

Python programs can be executed in several ways depending on your development environment and preferences.

Running Python in IDLE

IDLE (Integrated Development and Learning Environment) comes bundled with Python installation ?

  • Write your Python code and save it with a .py extension

  • To run the program, go to Run > Run Module or press F5

Example

print("Hello, World!")
print("Welcome to Python programming")
Hello, World!
Welcome to Python programming

Running from Command Line

Python scripts are saved with .py extension. After saving your script, you can run it from the Command Line by typing python followed by the filename ?

Example

If you have a script named hello.py, run it using ?

python hello.py

For Python 3 specifically, you might need to use ?

python3 hello.py

Running in PyCharm IDE

PyCharm is a popular IDE for Python development ?

  • Create a new Python file and save it (extension .py is added automatically)

  • Write your Python code in the file

  • Click the Green Play Button in the top-right corner, or

  • Right-click and select Run 'filename' option

The output will appear in the console window at the bottom of the IDE.

Interactive Mode (Python Shell)

Interactive mode allows you to write and execute Python code line by line. This is useful for testing small code snippets and learning ?

To enter interactive mode, open Command Prompt and type python then press Enter.

Example

Python 3.9.7 (default, Sep 16 2021, 16:59:28)
[MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello World")
Hello World
>>> x = 5
>>> y = 3
>>> print(x + y)
8
>>> exit()

Type exit() or press Ctrl+Z (Windows) / Ctrl+D (Mac/Linux) to exit interactive mode.

Running in Visual Studio Code

Visual Studio Code is a lightweight but powerful text editor with Python support ?

  • Create a file with .py extension, such as hello.py

  • Write your Python code in the file

  • Right-click and select Run Code, or press Ctrl+Alt+N

  • Alternatively, press F5 to run with debugging options

Comparison of Methods

Method Best For Features
IDLE Beginners Built-in, simple interface
Command Line Scripts, automation Fast execution, no GUI needed
PyCharm Large projects Advanced debugging, code completion
Interactive Mode Testing, learning Line-by-line execution
VS Code General development Lightweight, extensible

Conclusion

Choose the method that suits your needs: IDLE for learning, command line for scripts, IDEs like PyCharm for projects, and interactive mode for testing. Each method has its advantages depending on your development workflow.

---
Updated on: 2026-03-25T17:01:48+05:30

9K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements