---Advertisement---

How to Run Python Scripts : Comprehensive Step-by-Step Guide for Beginners 2025

By Bhavani

Published On:

---Advertisement---

πŸ‘‰How to Run Python Scripts : Step-by-Step Guide

Running Python scripts can be done in multiple ways, including via the command line, integrated development environments (IDEs), or file managers. This guide explains each method in detail.

A Python script is a file containing Python code with the .py extension. Scripts can be executed directly or imported as modules.

  1. Open the command line in interactive mode.
  2. Type the following command to start Python:

bash

python

  1. Write your Python code directly in the command prompt and press Enter to execute.

python

print(‘Hello World!’)

nginx

Hello World!


  1. Open the command prompt.
  2. Type python followed by the script file name (e.g., example.py).
  3. Ensure the script file is saved with the .py or .pyw extension.

bash

python example.py

nginx

Hello World!


Steps to Run Python Code in PyCharm IDE:

  1. Open PyCharm and create a new project.
  2. Name the project, select the root folder, and create a new Python file.
  3. Add your Python code in the newly created file.
  4. Right-click the file and select β€œRun File in Python Console.”

python

print(‘Hello World from PyCharm!’)

csharp

Hello World from PyCharm!


  1. Open Notepad and write your Python code.
  2. Save the file with the .py or .pyw extension.
  3. Right-click the file and choose β€œOpen with Python.”

python

print(‘Hello World from File Manager!’)

input(‘Press Enter to exit…’)


  1. Save your Python file as example.py.
  2. Copy the full file path.
  3. Open the command prompt and run the following command:

bash

python “C:/path/to/your/example.py”

vbnet

Hello World!

Press Enter to exit…


  1. Open the Linux terminal.
  2. Type the following command to start Python:

bash

python3

  1. Write and execute your Python code directly.

python

a = 25

b = 50

if a > b:

    print(“a is greater”)

else:

    print(“b is greater”)

csharp

b is greater

Alternatively, you can run the saved Python script file using:

bash

python3 /path/to/your/script.py


ParametersCodeModuleScript
DefinitionSeries of instructionsOrganized series of codesA file containing organized logic
ExecutionRun directly in Python interpreterImported and executedExecuted via Python interpreter

How to Check Python

---Advertisement---

Leave a Comment