Python #1 — Introduction & Setting Up
What Python is, why it's worth learning, how the interpreter works, and getting your environment ready with pyenv and VS Code.
Why Python?
Python is the most-used language for automation, data science, backend APIs, scripting, and AI tooling — not because it's the fastest, but because it's the most readable. You spend more time thinking about the problem than fighting the syntax.
A few things Python does differently from Java or JavaScript:
- No semicolons — newlines end statements
- Indentation is syntax — blocks are defined by indentation, not curly braces
- Dynamic typing — no type declarations required (optional type hints exist)
- The REPL — run code line by line interactively
Installing Python the Right Way
Don't use the system Python (/usr/bin/python). Use pyenv to manage versions cleanly.
macOS / Linux:
# Install pyenv
curl https://pyenv.run | bash
# Add to your shell config (~/.zshrc or ~/.bashrc)
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
# Restart your shell, then:
pyenv install 3.12.3
pyenv global 3.12.3
python --version # Python 3.12.3
Windows: Download from python.org — check "Add Python to PATH" during install. Or use pyenv-win.
Verify:
python --version # Python 3.12.x
pip --version # pip 24.x
On macOS/Linux, python might point to Python 2 (ancient). Always use python3 unless pyenv is active and you've set a global version. In this series we assume python = Python 3.
The Python REPL
Python has an interactive shell. Type python in your terminal:
>>> 2 + 2
4
>>> name = "Rupa"
>>> f"Hello, {name}!"
'Hello, Rupa!'
>>> type(name)
<class 'str'>
>>> exit()
Use the REPL constantly while learning. It gives you instant feedback.
Your First Program
Save as hello.py and run:
python hello.py
Notice:
- No class required — Python code can live at the top level
print()is a function call with parentheses (unlike Java'sSystem.out.println)- f-strings (
f"Hello, {name}!") are the modern way to embed variables in strings
Setting Up VS Code
- Install VS Code
- Install the Python extension by Microsoft
- Install Pylance for type checking and autocompletion
- Open a
.pyfile — VS Code detects Python and activates
Useful settings (settings.json):
{
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
"editor.formatOnSave": true,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
}
}
Install the Black formatter:
pip install black
Virtual Environments — Always Use One
A virtual environment isolates your project's dependencies. Never install packages globally.
# Create a virtual environment
python -m venv .venv
# Activate it
source .venv/bin/activate # macOS/Linux
.venv\Scripts\activate # Windows
# Your prompt changes to show (.venv)
(.venv) $ pip install requests
# Deactivate when done
deactivate
Always add .venv/ to your .gitignore.
# Save your dependencies
pip freeze > requirements.txt
# Restore in another environment
pip install -r requirements.txt
Creating a new .venv for every project prevents dependency conflicts. Project A needs requests==2.28 and project B needs requests==2.31? No problem — separate venvs.
How Python Runs Your Code
your script.py
→ Python reads it line by line
→ Compiles to bytecode (.pyc files in __pycache__)
→ CPython interpreter executes the bytecode
Unlike Java, there's no separate compile step you have to run. python script.py compiles and runs in one command.
What's Next?
Python #2 covers variables, data types, and strings in depth — Python's type system, type hints, and why f-strings are the only string formatting you need to know.
✦ Enjoyed this post?
Get posts like this in your inbox
No spam, just real tutorials when they're ready.
Discussion
Powered by GitHubComments use GitHub Discussions — no separate account needed if you have GitHub.