把数组['red','bluet','green','pink']的内容反转过来存放(for循环方法实现),输出['pink','green','bluet','red']
时间: 2023-10-23 19:20:47 浏览: 17
```python
colors = ['red', 'bluet', 'green', 'pink']
reverse_colors = []
for i in range(len(colors)-1, -1, -1):
reverse_colors.append(colors[i])
print(reverse_colors)
# 输出 ['pink', 'green', 'bluet', 'red']
```
使用range函数,从最后一个元素开始循环,每次循环将该元素添加到新的列表中,最终得到反转后的列表。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)