Computer Science 1026A/B Chapter Notes - Chapter 6: For Loop

26
COMPSCI 1026A/B Full Course Notes
Verified Note
26 documents
Document Summary
Lists: container that stores sequence of values listname = [342, 32, 423, 34, 4, 432, 645, 64] emptylist = [] Don"t create lists with unrelated meaning e. g. strings, letters, and numbers (age, bank account, shoe size?) Lists are sequence of elements that have integer positions or index. Similar to accessing characters, can access specific index in lists. Lists can hold any type values, strings are sequences of characters. List references specifies location of list copying list variables into another, both variables reference the same list can modify lists through either variable: scores = [element1, element2, element3, values = scores, scores[3] = 10. Be careful to not reference out of range list index: e. g. 8 elements means 0 to 7 index (logic error) call by values: parameter variable contents are unchanged. Filling a list with squares: element with index 0 contains 0^2 and index 1 contains 1^2 values = [] for i in range (n): values. append( i * i )