# list.py # The most important feature of the Python language is the list. # Often, we want to store many values for processing. # Let's create a new list, and call it L. L = [5, 4, 7, 3, 2, 6, 1] # The entire list is called L. But how do we refer to # one number in the list? We use brackets like this: # L[0] is the first number, L[1] is the 2nd number, etc. # Let's print the 3rd number: print "The third number is " print L[2] # Let's print all the numbers. print "Here are all the numbers in the list:" for number in L: print number # Let's find the sum of all the numbers: sum = 0 for number in L: sum = sum + number # Neat trick: In order to print a number on the same line as the # message that introduces it, there are 2 strategies: # 1. Put a comma after the text, like this: # print "The sum is ", # print sum # 2. Use just one print statement, and use concatenation: # print "The sum is " + str(sum) # In Python, if you want to print both a number and a string(text) # in the same statement, you need to put str() around the number. # This is similar to what we did with text functions in Excel. print "The sum is " + str(sum)