python-内建函数-反转函数reversed

1. 内建函数-反转函数reversed函数

  • reversed()函数: 返回一个反转的迭代器

  • 语法格式:

    reversed(seq)
    
  • 示例:列表反向

    n = [1, 2, 3]
    print(list(reversed(n)))
    

2. 内建函数-反转函数reversed函数案例

  • 案例:列表反向

    #!/usr/bin/env python3
    # _*_ coding: utf-8 _*_
    # Author:shichao
    # File: .py
    
    
    # 反向函数,reversed是返回的是一个对象
    s = [1,2,3]
    print(list(reversed(s)))
    
posted @ 2023-01-06 10:08  七月流星雨  阅读(229)  评论(0编辑  收藏  举报