File size: 1,663 Bytes
a7d7463 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | # 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"
```
|