Python Getting Started
Python Getting Started: Setup, CLI Checks, and First Script
Getting started with Python takes three quick steps: install Python 3, verify your terminal command, and run a .py file. Most macOS and Linux systems ship with Python preinstalled, while Windows users install it from python.org.
On Windows, check the Add Python to PATH box in the installer before clicking install. Skipping that checkbox prevents your terminal from finding the python command later.
Verifying Your Python Installation
Open your terminal or PowerShell window and check the installed version. Run one of the commands below depending on your operating system.
# Windows (PowerShell or Command Prompt)
python --version
# macOS and Linux
python3 --version
If you see Python 3.11.x or newer, your environment is ready. You can also launch the interactive shell (REPL) by typing python with no filename.
Running Code in the REPL vs. a Script File
The interactive shell runs one expression at a time, which helps you test small snippets quickly. For real programs, save your code in a file ending with .py and run it from your terminal.
# Save this file as greet_user.py
user_name = "Samira"
tasks_today = 4
print(f"Hello, {user_name}. You have {tasks_today} tasks today.")
Execute the script from the same folder:
python greet_user.py
Common Mistakes to Avoid
- Typing Python code inside the shell prompt: Commands like
python greet_user.pybelong in your system terminal, not inside the>>>Python prompt. - Forgetting to save before running: Editors do not auto-save by default, so save your
.pyfile before re-running it in the terminal. - Working in the wrong directory: If Python reports
No such file or directory, runpwdorcdto move into the folder holding your script.
Frequently Asked Questions
What editor should I use for Python?
VS Code with the official Microsoft Python extension works well for beginners and professionals. PyCharm Community Edition is another solid option with built-in debugging.
How do I exit the Python interactive shell?
Type exit() and press Enter, or press Ctrl+Z then Enter on Windows (Ctrl+D on macOS and Linux).
Should I use a virtual environment right away?
For single learning scripts, the global Python install works fine. Once you install third-party packages with pip, create a project venv to isolate dependencies.
Unlock Your
Full Potential.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Try it Yourself
Experiment with the code from this lesson in our interactive playground.