Printing list in Python with serial numbers

This question already has an answer here:

  • Accessing the index in 'for' loops? 17 answers

  • Use enumerate

    a = ['dwe','fw4fe4f','gvfes','fw4f',44,'vwe4d','sv','vsed']
    for i,each in enumerate(a,start=1):
        print ("{}.{}".format(i,each))
    

    Output ..

    1.dwe
    2.fw4fe4f
    3.gvfes
    4.fw4f
    5.44
    6.vwe4d
    7.sv
    8.vsed
    

    a = ['dwe','fw4fe4f','gvfes','fw4f',44,'vwe4d','sv','vsed']
    
    for i,j in enumerate(a):
        print "%s. %s"%(i+1,j)
    
    >> 1. dwe
       2. fw4fe4f
       3. gvfes
       4. fw4f
       5. 44
       6. vwe4d
       7. sv
       8. vsed
    
    链接地址: http://www.djcxy.com/p/24016.html

    上一篇: 查找包含值Python的列表的所有索引

    下一篇: 使用序列号在Python中打印列表