Python list list of a variety of access methods to traverse

    # List are several access methods can be used depending on the situation. 

List
= [ ' 0 ' , ' . 1 ' , ' 2 ' , ' . 3 ' ] # Method. 1 Print ' traversal list Method. 1: ' for I in List: Print ( " ID:% s value:% s " % (list.index (I) , I)) Print ' \ n-list traversal Method 2: ' # Method 2 for I in Range (len (List)): Print ( " ID:% s value:% s " % (I , List [I])) # Method. 3 Print ' \ n-list traversal methods. 3: ' for I, Val in the enumerate (List): Print ( " ID:% s value:% s " % (I , Val)) # Method 3 Print ' \ n-3 through the list method, the parameter value of 1, only the described number counted from an original count generally starting from 0: ' for I, Val in the enumerate (List, 1 ): Print ( " ID:% s value:% s " % (I, Val))

 

Guess you like

Origin www.cnblogs.com/an-wl/p/12411403.html