Skip to content

Latest commit

 

History

History
112 lines (93 loc) · 3.65 KB

File metadata and controls

112 lines (93 loc) · 3.65 KB

Python Mastery: Reference & Study Guide

1. Core Data Structures with Snippets

  • Lists: items = [1, 2, 3]; items.append(4)
  • Dictionaries: user = {"id": 1, "name": "Alice"}; print(user["name"])
  • Tuples: point = (10, 20) # Immutable
  • Sets: unique = {1, 2, 2, 3} # Result: {1, 2, 3}

2. Control Flow & Logic

# List Comprehension
squares = [x**2 for x in range(5)] # [0, 1, 4, 9, 16]

# Context Manager
with open("test.txt", "w") as f:
    f.write("Hello World")

# Decorator Example
def debug(func):
    def wrapper(*args):
        print(f"Calling {func.__name__}")
        return func(*args)
    return wrapper

@debug
def greet(name):
    return f"Hi {name}"

3. Tooling Cheat Sheet & PyCharm Essentials

Task Command / Shortcut
Virtual Env python -m venv .venv
Install Package pip install <package_name>
Run Current File Shift + F10 (PyCharm)
Debug Current File Shift + F9 (PyCharm)
Toggle Breakpoint Ctrl + F8 (PyCharm)
Step Over (Next Line) F8 (While Debugging)
Step Into (Function) F7 (While Debugging)
Resume Program F9 (While Debugging)

Quick Logic Reference

  • Conditional Expressions: result = "Pass" if score > 50 else "Fail"
  • Logical Truthiness: 0, "", [], {}, None are all False. Everything else is True.
  • Debugging Tip: Use Conditional Breakpoints (Right-click a red dot) to pause a loop only when a specific value is met (e.g., i == 50).

4. Deep Dives (FastAPI & Pandas)

FastAPI Snippet:

from fastapi import FastAPI
app = FastAPI()

@app.get("/")
def read_root():
    return {"status": "online"}

Pandas Snippet:

import pandas as pd
df = pd.read_csv("data.csv")
print(df.describe()) # Statistical summary

5. The Python Mastery Roadmap (Specified Path)

Phase 1: The Foundation (Week 1-2)

Focus on syntax and basic problem solving.

  • Variables, Data Types (Int, String, Float, Boolean).
  • Basic Operators and Math.
  • Conditional Logic (if/elif/else).
  • Loops (for and while).
  • Functions and Scope.

Phase 2: Data Handling & Logic (Week 3-4)

Mastering collections and efficiency.

  • List/Dict/Set operations.
  • List Comprehensions.
  • File I/O (Reading/Writing files).
  • Exception Handling (try/except/finally).
  • Working with JSON and external data.

Phase 3: Object-Oriented Programming (Week 5-6)

Thinking in systems and structures.

  • Classes and Objects.
  • Inheritance and Polymorphism.
  • Encapsulation (Private variables).
  • Dunder Methods (__init__, __str__, __repr__).
  • Type Hinting.

Phase 4: Specialization & Ecosystem (Week 7+)

Pick a path based on your goals.

  • Web Development: FastAPI, SQL Alchemy, Pydantic.
  • Data Science: NumPy, Pandas, Matplotlib, Scikit-learn.
  • Automation: Requests, BeautifulSoup, Selenium.
  • Testing: Pytest, Mocking.

6. Dependency Management & Pip Workflows

Managing libraries correctly is the difference between "it works on my machine" and "it works everywhere."

Core Commands

Action Command Description
Install pip install <package> Installs the latest version of a library.
Snapshot pip freeze > requirements.txt Saves all currently installed versions to a file.
Sync pip install -r requirements.txt Installs everything listed in the requirements file.
Check pip list Shows all installed packages and their versions.
Uninstall pip uninstall <package> Removes a package from the environment.