CECS 174 Lecture Notes - Lecture 7: Alphabet Inc., Ab3, Sega

57 views7 pages

Document Summary

# a tuple is an ordered grouping of data values under one name. Except that tuples are immutable -- once made, they can"t. # parentheses surrounding a comma-separated sequence creates a tuple, similar to. # the tuple me has 3 elements in it. # we can use square brackets to index a tuple just like a list, but i don"t. I prefer to unpack them: (my_first, my_last, my_age) = me print(my_last) # this takes the first element of me and assigns it to the variable my_first. # all values of a tuple must be unpacked at once -- can"t access just one. me = (neal, terrell, 22) # otherwise tuples are like any other value student = (bob, roberts, 19) student_first, student_last, student_age = student. # we can make lists of tuples, too people = [(mike, michaelson, 21), (jennifer, johnson, 23)] student_first, student_last, student_age = people[1] print(student_first)

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