zoukankan      html  css  js  c++  java
  • enumerate()函数的用法

    # enumerate() 函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列,同时列出数据和数据下标,
    # 一般用在 for 循环当中。
    
    
    # 作用就是:将可迭代对象中的元素和索引同时取出
    
    
    seq = ['one', 'two', 'three']
    for i, element in enumerate(seq):
        print(i, element)
    
    # 0 one
    # 1 two
    # 2 three
    
    # start 说明索引起始的位置
    seq = ['one', 'two', 'three']
    for i, element in enumerate(seq, start=1):
        print(i, element)
    
    
    # 1 one
    # 2 two
    # 3 three# enumerate() 函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列,同时列出数据和数据下标,
    # 一般用在 for 循环当中。
    
    
    # 作用就是:将可迭代对象中的元素和索引同时取出
    
    
    seq = ['one', 'two', 'three']
    for i, element in enumerate(seq):
        print(i, element)
    
    # 0 one
    # 1 two
    # 2 three
    
    # start 说明索引起始的位置
    seq = ['one', 'two', 'three']
    for i, element in enumerate(seq, start=1):
        print(i, element)
    
    
    # 1 one
    # 2 two
    # 3 three
    
  • 相关阅读:
    初学AOP
    通过工厂方式配置bean
    Spring中Bean的生命周期方法
    Spring中配置文件中引用外部文件
    Spring中的SPEL
    Spring中的自动装配
    初学Spring
    暑假写的有关字符串处理的程序
    linux查看所有用户信息
    python 函数enumerate(x,y)的用法
  • 原文地址:https://www.cnblogs.com/hui-code/p/12689160.html
Copyright © 2011-2022 走看看