Appending items to a list. : loop through « List « Python Tutorial






playList = []     # list of favorite plays

for i in range( 5 ):
   playName = raw_input( "Play %d: " % ( i + 1 ) )
   playList.append( playName )
   
print "\nSubscript     Value"

for i in range( len( playList ) ):
   print "%9d     %-25s" % ( i + 1, playList[ i ] )








7.16.loop through
7.16.1.Iterating by Sequence Item
7.16.2.Iterating by Sequence Index
7.16.3.Appending items to a list.