Skip to content

Commit c6c5b83

Browse files
committedAug 15, 2024
context-manager has been added
1 parent 32f2a0d commit c6c5b83

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
 

‎11-advanced-topics/README.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
This collection includes explanations and examples of several advanced Python concepts that are crucial for mastering Python and writing more efficient, clean, and effective code.
2+
3+
## Table of Contents
4+
5+
1. [Decorators](#decorators)
6+
2. [Generators and Iterators](#generators-and-iterators)
7+
3. [Context Managers](#context-managers)
8+
9+
## Decorators
10+
11+
**File:** `decorators.py`
12+
13+
Decorators are a powerful feature in Python that allows you to modify the behavior of a function or class method. They are essentially functions that wrap another function, modifying or extending its behavior without changing its actual code.
14+
15+
### Key Points:
16+
17+
- **Iterators:** Objects that implement the `__iter__()` and `__next__()` methods. They allow you to iterate through a sequence of values.
18+
19+
- **Generators:** A simpler way to create iterators using functions with `yield` statements. They generate values on-the-fly and are memory efficient.
20+
21+
- **Syntax:** Decorators are applied using the `@decorator_name` syntax above a function definition.
22+
23+
- **Use Cases:** Common uses include logging, access control, instrumentation, and caching.
24+
25+
26+
## File: `context_managers.py`
27+
28+
Context managers are used to manage resources, such as file streams, network connections, or database connections, ensuring they are properly cleaned up after use. They help avoid resource leaks by automatically handling setup and teardown.
29+
30+
### Key Points:
31+
32+
- **Syntax:** Context managers are commonly used with the `with` statement.
33+
34+
- **Custom Context Managers:** You can create custom context managers using classes with `__enter__()` and `__exit__()` methods or by using the `contextlib` module.
35+
36+

0 commit comments

Comments
 (0)
Please sign in to comment.