# Python Setup & Language Basics Python is the language of data science. Its clean syntax, massive ecosystem of libraries, and active community make it the go-to choice for analysts, engineers, and researchers worldwide. ## Installation 1. Download Python 3.11+ from [python.org](https://python.org) 2. Install with the "Add to PATH" option checked 3. Verify: `python --version` 4. Create a virtual environment: `python -m venv venv` 5. Activate it: `source venv/bin/activate` (Mac/Linux) or `venv\Scripts\activate` (Windows) ## Variables & Data Types ```python # Python is dynamically typed — no declaration needed name = "Alice" # str age = 28 # int score = 94.5 # float is_pro = True # bool tags = ["ml", "python"] # list profile = {"role": "admin"} # dict coords = (12.9, 77.5) # tuple (immutable) ``` ## Control Flow ```python # If / elif / else grade = 85 if grade >= 90: print("A") elif grade >= 80: print("B") # → "B" else: print("C") # For loops fruits = ["apple", "banana", "cherry"] for fruit in fruits: print(fruit.upper()) # List comprehension — Pythonic! squares = [x**2 for x in range(10)] # [0, 1, 4, 9, 16, …] evens = [x for x in range(20) if x % 2 == 0] ``` ## Functions ```python def calculate_bmi(weight_kg: float, height_m: float) -> float: """Calculate Body Mass Index.""" return weight_kg / (height_m ** 2) bmi = calculate_bmi(70, 1.75) print(f"Your BMI is {bmi:.1f}") # f-string formatting # Lambda (anonymous function) double = lambda x: x * 2 print(double(5)) # 10 ``` ## Why Python for Data Science? | Library | Purpose | |--------------|-------------------------------------| | NumPy | Fast numerical arrays & math | | Pandas | Data manipulation & analysis | | Matplotlib | Plotting & visualisation | | Scikit-learn | Machine learning algorithms | | TensorFlow | Deep learning | In this course we'll use all of the first four extensively. Let's dive in! 🐍