| # Python Skills | |
| ## Python Basics | |
| ### Variables | |
| ```python | |
| name = "Python" | |
| age = 25 | |
| is_active = True | |
| ``` | |
| ### Data Types | |
| - **int** - Integer: `42` | |
| - **float** - Decimal: `3.14` | |
| - **str** - String: `"Hello"` | |
| - **bool** - Boolean: `True/False` | |
| - **list** - List: `[1, 2, 3]` | |
| - **dict** - Dictionary: `{"key": "value"}` | |
| ### Functions | |
| ```python | |
| def greet(name: str) -> str: | |
| """Return a greeting message.""" | |
| return f"Hello, {name}!" | |
| # Lambda function | |
| square = lambda x: x ** 2 | |
| ``` | |
| ### Control Flow | |
| ```python | |
| if condition: | |
| do_something() | |
| elif other_condition: | |
| do_other() | |
| else: | |
| do_default() | |
| ``` | |
| ### Loops | |
| ```python | |
| # For loop | |
| for item in items: | |
| print(item) | |
| # While loop | |
| while condition: | |
| do_something() | |
| ``` | |
| ## Advanced Topics | |
| ### Decorators | |
| ```python | |
| def my_decorator(func): | |
| def wrapper(): | |
| print("Before") | |
| func() | |
| print("After") | |
| return wrapper | |
| @my_decorator | |
| def say_hello(): | |
| print("Hello!") | |
| ``` | |
| ### Classes | |
| ```python | |
| class Person: | |
| def __init__(self, name: str, age: int): | |
| self.name = name | |
| self.age = age | |
| def __str__(self) -> str: | |
| return f"{self.name}, {self.age} years old" | |
| ``` | |
| ### Exception Handling | |
| ```python | |
| try: | |
| result = risky_operation() | |
| except ValueError as e: | |
| print(f"Error: {e}") | |
| finally: | |
| cleanup() | |
| ``` | |
| ### List Comprehensions | |
| ```python | |
| squares = [x**2 for x in range(10)] | |
| evens = [x for x in range(20) if x % 2 == 0] | |
| ``` | |
| ### Context Managers | |
| ```python | |
| with open('file.txt', 'r') as f: | |
| content = f.read() | |
| ``` | |
| ### Async/Await (asyncio) | |
| ```python | |
| import asyncio | |
| async def fetch_data(): | |
| await asyncio.sleep(1) | |
| return "data" | |
| ``` | |