# Python :::spoiler {state="open"} **🧷 Table of Content** <br/> - __Root:__ **[Web Development](/Kt7xgfDNQJq12DduZa0nfw)** - __Programming Language__ [toc] ::: <br/> ## 1. Introduction - **Purpose**: Python is a general-purpose programming language widely used in web development, data analysis, machine learning, game development, scripting, automation, and more. - **Features**: - Simple and readable syntax that facilitates fast development and maintenance. - Comes with a powerful standard library supporting a wide range of common tasks. - Has a vast third-party package ecosystem (e.g., `PyPI`) to extend functionality. - High-level language that supports multiple programming paradigms (object-oriented, functional, procedural). - ==Basic Syntax==: 1. ++Variables and data types++: (`int`, `float`, `str`, `list`, `dict`, `tuple`, `set`) 2. ++Control flow++: (`if`, `for`, `while`) 3. ++Function definition++: `def`, arguments, return values 4. ++Modules and imports++ (`import`) 5. ++Exception handling++ (`try` / `except`) 6. ++List comprehensions & lambda expressions++ 7. ++Object-Oriented Programming++ (`class`, `method`, `self`) - ==Built-in Data Structures==: - `list` → ordered, mutable - `tuple` → ordered, immutable - `set` → unordered, unique elements - `dict` → key-value pairs - `heapq` → priority queues (min-heap) - `deque` → from `collections`, fast append/pop from both ends - other `collections` → `Counter`, `defaultdict`, `OrderedDict` - ==Important Libraries==: - _Data Processing & Analysis_ : 1. `NumPy`: Efficient numerical computation and array operations 2. `Pandas`: Data manipulation and tabular data (DataFrame) - _Data Visualization_ : 1. `Matplotlib`: Basic plotting and charting 2. `Seaborn`: Statistical data visualization built on top of Matplotlib 3. `Plotly`: Interactive charts and dashboards - _Automation & Web Scraping_ : 1. `Requests`: HTTP client for web requests 2. `BeautifulSoup` / `lxml`: HTML parsing 3. `Selenium`: Browser automation - _Development & Testing Tools_ : 1. `unittest` / `pytest`: Testing frameworks 2. `virtualenv` / `pipenv`: Virtual environments and dependency management <br/> ## 2. Functions and Tools - **Anonymous Functions**: `lambda` - Define small, unnamed functions: `lambda args: expression` - Commonly used in `map()`, `filter()`, `sorted(key=...)`, etc. - **Map, Filter, and Zip**: - `map(func, iterable)`: Applies a function to each item in the iterable. - `filter(func, iterable)`: Filters items based on a boolean function. - `zip(iter1, iter2)`: Combines multiple iterables into tuples. - ==`functools` _[🔗](/Sy8SFs1lxe)_== : - **Reduction**: `functools.reduce`: - `reduce(function, iterable, initializer?)` - Reduces an iterable to a single value using a function. - **Partial Functions**: `functools.partial` - Fixes some arguments of a function and returns a new function. - **Memoization**: `functools.lru_cache` - Caches results of expensive function calls. - Simply add a __decorator__ to enable. - **`Itertools`**: A module provides advanced iteration utilities: - `itertools.chain(*iterables)`: Concatenate multiple iterables - `accumulate(iterable)`: Cumulative sums - `product(iter1, iter2)`: Cartesian product - `permutations(iterable, r)`: All r-length permutations - `combinations(iterable, r)`: All r-length combinations - `groupby(iterable, key)`: Group items by a key (requires sorting) - **`yield`**: - Generators create lazy iterators using `yield`, saving memory <br/> ## 3. Decorators - **Definition**: A decorator is a higher-order function that allows you to modify the behavior of functions or methods. - **Creating & Using**: Syntax for creating decorators, usage of `@decorator_name`. - **Example**: - Simple function decorators - Example using `@njit` (from NumPy/Numba for JIT compilation). - **Higher-Order Functions**: Explanation of wrappers and how decorators use them. <br/> ## 4. Iterators and Generators - **Iterators**: Explanation of the iterator protocol (`__iter__()` and `__next__()`). - **Generators**: - Using `yield` to create generator functions. - Generator expressions (similar to list comprehensions). - **Generator Object**: Discussion of how generators are iterable objects. - **Itertools**: Common utilities from the `itertools` library (e.g., `chain`, `combinations`, `permutations`). <br/> ## 5. Concurrency - **Concurrency Concepts**: Definition and examples of concurrency, multitasking. - **Multithreading**: - Using Python’s `threading` module. - Global Interpreter Lock (GIL) and its impact on Python threads. - **Asynchronous Programming**: - Usage of `asyncio` for async I/O operations. - Using `concurrent.futures` for parallelism. - Example: async function with `asyncio`. <br/> ## 6. Logging - **Logging Principles**: Why logging is important in applications. - **Logging Levels**: DEBUG, INFO, WARNING, ERROR, CRITICAL. - **Logging Handlers**: FileHandler, StreamHandler, RotatingFileHandler. - **Basic Configuration**: - Using `logging.basicConfig()`. - Example of creating custom loggers, handlers, and formatters. - Writing logs to a file and rotating logs. <br/> ## 7. Pygame - **Introduction to GameDev Concepts**: Overview of game elements such as surfaces, sprites, and collisions. - **Basic Game Elements**: - Surfaces, sprites, and handling input events. - Collision detection (`collidepoint`). - **Graphics Libraries**: Integration with other libraries like OpenGL and OpenCV. - **Example**: Simple puzzle game with Pygame. <br/> ## 8. Web Frameworks ### Django - **MVC Pattern**: Explanation of the Model-View-Controller pattern. - **ORM**: Using Django’s Object-Relational Mapping (ORM) system for database operations. - **Form Handling**: Creating and processing HTML forms in Django. - **Templating**: Using Django’s templating language for dynamic content. ### Flask - **Routing and Middleware**: Handling routes and middleware in Flask. - **Request Handling**: Processing GET, POST requests. - **Blueprints**: Organizing large Flask applications with blueprints. - **Integration with Frontend**: Using Jinja2 templates, integrating with AJAX for frontend interactions. <br/> ## 9. Machine Learning ### Basic Concepts - **Supervised vs. Unsupervised Learning**: Definition and key differences. - **Regression vs. Classification**: Differences and examples. ### Libraries - **NumPy & Pandas**: - Data manipulation and analysis. - Examples of data handling with `DataFrame`. - **Scikit-Learn**: - Training and evaluating models. - Common algorithms like Linear Regression, Decision Trees, SVM. ### Deep Learning - **TensorFlow & Keras**: - Building and training neural networks. - Hyperparameter tuning and evaluation. - **PyTorch**: - Tensors, autograd, and building neural networks. - Custom training loops. <br/> ## 10. Model Deployment - **ONNX**: - Exporting models in the Open Neural Network Exchange format. - Integration with other frameworks. - **Serving Models**: - Using Flask or FastAPI to serve machine learning models as APIs. <br/> ## 11. Advanced Topics ### Algorithms (Python Practice) - **Sorting algorithms**: Bubble, Insertion, Merge Sort, Quick Sort - **Searching algorithms**: Linear Search, Binary Search - **Backtracking** - **Greedy algorithms** - **Graph traversal**: DFS, BFS (with `queue`, `deque`) - **Recursion & divide and conquer** - **Dynamic Programming** (memoization, tabulation) - **Big-O notation** & **complexity analysis** ### Transfer Learning - **Transfer Learning**: Reusing pre-trained models for new tasks. - **Fine-Tuning**: Adjusting pre-trained models for specific datasets. ### GANs - **Generative Adversarial Networks (GANs)**: Overview of GANs, how they work, and common applications. ### Reinforcement Learning - **Basic Concepts**: Overview of reinforcement learning, agents, actions, rewards, and environment. <br/> :::spoiler __Relevant Resources__ #### • [Python 基礎語法系列](/rirdIkdWRh6Thlx93gJ6YQ) :::