''' Support your understanding of lists list building ''' # get some lists print() # create and add to values values = [ ] values.append( "u" ) values.append( "v" ) values.append( "a" ) values.append( "!" ) values.append( " " ) values.append( "u" ) values.append( "v" ) values.append( "a" ) values.append( "!" ) # listvariable.append( value to add to list) # append() function adds the thing in parentheses to the list the function is called on! # append() adds to the END of a list # You can append anything you want to the end of a list (string, number, etc.) print( "values =", values ) input( 'Enter when ready: ' ) # input() waits for user input (and the Enter key) to proceed with the rest of the code # Example of accumulation (building up a list of numbers) # ints = [] is the accumulator # for i in range(0,10): # ints.append( i ) # Modifying list (building up list) # Recall range(i,j) goes from i to j-1 # If you want to include j, just go from range(i, j+1) to include the j value # range(0,11) is 0 1 2 3 4 5 6 7 8 9 10 (to include that 10 so that it's 10 + 1 / 11) # or range(0, 10 + 1) # create and add to ints ints = [] for i in range( 0, 10 ) : # The loop variable i changes value to each value in our sequence (range 0-9) print( 'Loop variable: ', i ) ints = ints.append( i ) # Adds each number from 0-9 one by one into the list ints print( 'The list ints:', ints ) print() print( "ints =", ints ) # You don't want to do list_accumulator = list_accumulator.append(i) # You just want to call list_accumulator.append(i) directly! # The append() function hands back None. Therefore, when we store the value of the # function call append() in ints, it stores None and that's not what we want! # Since lists are MUTABLE (changeable), we just want to change it directly by calling # the function on it # list_accumulator.append( what we wanna put in it ) # End up with a list [0,1,2,3,4,5,6,7,8,9]