CS 110 Lecture Notes - Lecture 12: Tuple
Document Summary
It is possible to create a list of lists. Calls the value at [0] of the [0] list. It is possible to use multiple variables to store the x value, y value, and direction it"s facing; this code would be longer than necessary. The best way to store multiple variables that do not need to be changed within one iteration is by using tuples. Tuples are immutable; the value of a tuple cannot be changed once it is created: strlist = (1,2,3) This creates a tuple; notice the parentheses, instead of square brackets. Tuples throw an error if you try to change them in any way. Tuples can be used for multiple assignments in one line: robot = [ johnny", 5,1986, s. a. i. n. t", (name, number, year, model) = robot. This will assign each value in robot to the corresponding variable. Tuples also allow assignment of multiple variables: def returnmulti():