当然可以,以下是使用列表实现的迭代器、生成器和装饰器示例:
1. 迭代器
```python
my_list = [1, 2, 3]
my_iterator = iter(my_list)
while True:
try:
item = next(my_iterator)
print(item)
except StopIteration:
break
```
输出:
```
1
2
3
```
2. 生成器
```python
def my_generator(data):
for item in data:
yield item * 2
my_data = [1, 2, 3]
my_generator_obj = my_generator(my_data)
for item in my_generator_obj:
print(item)
```
输出:
```
2
4
6
```
3. 装饰器
```python
def my_decorator(func):
def wrapper():
print("Before function call")
func()
print("After function call")
return wrapper
@my_decorator
def say_hello():
print("Hello")
say_hello()
```
输出:
```
Before function call
Hello
After function call
```