python traverse the list

Through the listthe output of all the elements

  1. Sequentially through the list
    renderings:

    Code:

    # Create a list 
    stus = [ ' Monkey ' , ' pig ' , ' sand monk ' , ' monk ' , ' White Skeleton ' , ' spider ' ] 
    
    # sequentially through the list 
    Print (stus [0])
     Print (stus [. 1 ])
     Print (stus [2 ])
     Print (stus [. 3])

     

  2. By traversing the list while loop
    renderings:

    Code:

    # Create a list 
    stus = [ ' Monkey ' , ' pig ' , ' sand monk ' , ' monk ' , ' White Skeleton ' , ' spider ' ]
     # by looping through the list while 
    I = 0
     while I < len (stus):
         Print (stus [I]) 
        I + =. 1

     

  3. By looping through the list for    the best method of traversing
    renderings:

    Code:

    # Create a list 
    stus = [ ' Monkey ' , ' pig ' , ' sand monk ' , ' monk ' , ' White Skeleton ' , ' spider ' ]
     # for loop through the list 
    for I in stus:
         Print (I)

     


Guess you like

Origin www.cnblogs.com/FlyingLiao/p/11184749.html