Python Getting Started 🚀
Installation
To start coding in Python, you need to have the Python interpreter installed on your computer. Many modern systems (Mac, Linux) come with Python pre-installed.
🔍 Check if Python is Installed
Open your terminal (Mac/Linux) or Command Prompt (Windows) and type:
python --version# ORpython3 --version
⚠️ Watch Out: Python 2 vs 3
If you see version 2.x.x, that is an old legacy version. You must install Python 3 (e.g., 3.10 or newer) to follow this course.
⬇️ How to Install Python
🪟 Windows
- Go to python.org.
- Download the latest version.
- Crucial: Check "Add Python to PATH".
🍎 macOS
- Install via Homebrew (Recommended):
brew install python - Or download the installer from python.org.
🐧 Linux
- Usually pre-installed.
- Update via package manager:
sudo apt-get install python3
✨ Pro Tip: "Add to PATH"
On Windows, if you forget to check "Add Python to PATH", your computer won't know where to find the python command. You'll have to reinstall or manually edit environment variables (which is a pain!).
✨ Your First Python Program
Python is an interpreted language. You write code in a text file (usually with a .py extension) and the interpreter executes it.
Step 1: Create a file
Create a file named helloworld.py and add this code:
print("Hello, World!")Step 2: Run the file
Open your terminal/command prompt, navigate to the file's folder, and run:
python helloworld.py
Output:
Hello, World!
💻 The Python REPL (Shell)
For quick experiments, you can run Python code directly in the command line without a file. This is called the REPL (Read-Eval-Print Loop).
$ pythonPython 3.10.4 (main, Mar 23 2022, 23:05:40) [Clang 13.0.0] on darwinType "help", "copyright", "credits" or "license" for more information.>>> print("Hello, World!")Hello, World!>>> 5 + 510>>> exit()
💡 Pro Tip: Use an IDE
While you can write Python in Notepad, using an Integrated Development Environment (IDE) makes life much easier. Popular choices include:
- VS Code: Lightweight, free, and powerful (Recommended).
- PyCharm: Full-featured IDE specifically for Python.
- Jupyter Notebook: Great for data science and learning.
⚠️ Watch Out!
On many systems, python might refer to Python 2, while python3 refers to Python 3. Always check the version! If python doesn't work, try python3.