admin管理员组

文章数量:1794759

python全栈开发《39.列表的reverse函数》

1.reverse的功能

对当前列表顺序进行反转。

2.reverse的用法

代码语言:javascript代码运行次数:0运行复制
drinks = ['雪碧','可乐','矿泉水']
drinks.reverse()
print(drinks)

运行结果:

代码语言:javascript代码运行次数:0运行复制
/Users/llq/PycharmProjects/pythonlearn/pythonlearn/python_list/bin/python /Users/llq/PycharmProjects/pythonlearn/python_list/1.py 
['矿泉水', '可乐', '雪碧']

进程已结束,退出代码为 0

3.代码

代码语言:javascript代码运行次数:0运行复制
# coding:utf-8

students = [
    {'name':'dewei','age':33,'top':174},
    {'name':'小编','age':10,'top':175},
    {'name': 'xiaogao', 'age': 18, 'top': 188},
    {'name': 'xiaoyun', 'age': 18, 'top': 165}
]

print('当前的同学顺序是{}'.format(students))
students.reverse()
print('座位更换之后的顺序是{}'.format(students))

运行结果:

代码语言:javascript代码运行次数:0运行复制
/Users/llq/PycharmProjects/pythonlearn/pythonlearn/python_list/bin/python /Users/llq/PycharmProjects/pythonlearn/python_list/list_reverse.py 
当前的同学顺序是[{'name': 'dewei', 'age': 33, 'top': 174}, {'name': '小编', 'age': 10, 'top': 175}, {'name': 'xiaogao', 'age': 18, 'top': 188}, {'name': 'xiaoyun', 'age': 18, 'top': 165}]
座位更换之后的顺序是[{'name': 'xiaoyun', 'age': 18, 'top': 165}, {'name': 'xiaogao', 'age': 18, 'top': 188}, {'name': '小编', 'age': 10, 'top': 175}, {'name': 'dewei', 'age': 33, 'top': 174}]

进程已结束,退出代码为 0

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。原始发表:2024-09-23,如有侵权请联系 cloudcommunity@tencent 删除函数开发全栈pythonreverse

本文标签: python全栈开发《39列表的reverse函数》