CS 110 Lecture Notes - Lecture 12: Tuple

92 views2 pages
25 Oct 2016
Course
Professor

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():

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents