Below is a clear, complete, exam-oriented explanation of Running Python, covering all important methods: interactive mode, script mode, IDEs, command line, and editors. Suitable for BCA/MCA/B.Tech students.
Running Python
Once Python is installed, you can run Python programs in different ways depending on your requirement. Python provides two primary modes of execution:
- Interactive Mode (Python Shell / REPL)
- Script Mode (Running .py files)
Along with this, Python can also be run using:
- IDLE
- VS Code
- PyCharm
- Jupyter Notebook
- Command Line Terminal
1. Running Python in Interactive Mode (Python Shell / REPL)
Interactive mode lets you execute Python commands line by line.
It is useful for:
- Testing small code snippets
- Learning Python
- Checking output quickly
How to open Python Interactive Shell:
Windows:
Open Command Prompt and type:
python
macOS/Linux:
python3
You will see the Python prompt:
>>>
Example in interactive mode:
>>> print("Hello")
Hello
>>> 5 + 6
11
Exit interactive mode:
>>> exit()
or press Ctrl + Z (Windows) or Ctrl + D (macOS/Linux)
2. Running Python in Script Mode (Using .py Files)
Script mode is used for writing full Python programs in files ending with .py extension.
Steps:
- Open a text editor (Notepad, VS Code, Sublime, PyCharm, etc.)
- Create a file:
example.py - Write Python code:
print("Python Script Mode Example") - Save the file.
Run the file from Command Prompt/Terminal:
Windows:
python example.py
macOS/Linux:
python3 example.py
This executes the program and shows output.
3. Running Python Using IDLE
IDLE (Integrated Development and Learning Environment) comes bundled with Python.
To open IDLE:
- Windows Start Menu → Search IDLE
- macOS/Linux → depending on installation
IDLE provides:
- Python shell (interactive mode)
- Editor window (script mode)
Steps to run using IDLE:
- Open IDLE
- Click File → New File
- Write code:
print("Hello from IDLE") - Save (Ctrl + S)
- Run → Run Module (F5)
Output appears in Python Shell.
4. Running Python in VS Code
VS Code is one of the most popular editors.
Steps:
- Install VS Code
- Install the Python Extension
- Create a file with
.pyextension - Write your code
- Click Run > Run Without Debugging
- Output appears in the terminal
5. Running Python in PyCharm
PyCharm is a dedicated Python IDE.
Steps:
- Install PyCharm
- Create a new project
- Create a Python file
- Write code
- Click the Run button
PyCharm automatically handles Python interpreter paths.
6. Running Python in Jupyter Notebook
Used in Data Science and Machine Learning.
Steps:
Run:
jupyter notebook
Create Python notebook:
File → New → Python 3
Write code inside cells and press Shift + Enter to execute.
7. Running Python Using Command Line Arguments
You can pass arguments to Python scripts.
Example script: add.py
import sys
print("Arguments:", sys.argv)
Run:
python add.py 10 20
Output:
Arguments: ['add.py', '10', '20']
8. Using “python -c” to run one-line commands
You can run quick commands without opening interactive mode:
python -c "print(5*5)"
Output:
25
9. Running Python Using an Online Compiler
If Python is not installed, you can use:
- Replit
- Google Colab
- Jupyter Notebook online
- Programiz / HackerRank / TutorialsPoint editors
Summary Table: Running Python
| Method | Description | Best Use |
|---|---|---|
| Interactive mode | Run line-by-line in Python shell | Testing small code |
| Script mode | Run .py files | Full programs |
| IDLE | Built-in Python IDE | Beginners |
| VS Code | Editor with extensions | Most common |
| PyCharm | Full IDE | Professional development |
| Jupyter Notebook | Cell-based | Data science |
| Terminal commands | python -c | Quick tasks |
| Online compilers | Browser-based | No installation required |
