Through the list : the output of all the elements
- 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])
- 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
- 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)