Running Python
Run Python code from a file or interactively in the REPL.
Syntax
python hello.pyThere are two main ways to run Python code.
1. Run a script file
Save your code in a file ending in .py, then run it from the terminal with python filename.py.
2. The interactive REPL
Type python with no filename to open the REPL (Read-Eval-Print Loop). You type one line, press Enter, and see the result instantly. It is perfect for quick experiments. Type exit() to leave.
Example
Loading editor…
Press Run to execute the code.
When to use it
- A developer runs a data processing script from the terminal each morning to generate reports.
- A learner opens the REPL to quickly test how a string method behaves.
- A CI pipeline executes a Python test file automatically on every code push.
More examples
Run a script file
Shows the standard way to execute a Python source file from the terminal.
# Save this as hello.py:
# name = 'Ada'
# print('Hello,', name)
python hello.py
# Output: Hello, AdaUse the REPL interactively
Demonstrates typing expressions into the REPL and seeing results without print().
# Inside the Python REPL (started with: python3)
>>> x = 7
>>> x * 6
42
>>> 'hello'.upper()
'HELLO'
>>> exit()Run one-liner from terminal
Uses the -c flag to run a short Python expression directly in the shell.
python3 -c "print('Hello from the command line')"
# Output:
# Hello from the command line
Discussion