CECS 174 Lecture Notes - Lecture 6: 5,6,7,8, Valar Dohaeris, Valar Morghulis

72 views9 pages

Document Summary

# lists are mutable -- they can be mutated, or changed, both by. # changing individual indices, or by adding or removing values. It changes one aspect of the variable faculty, # but doesn"t create a brand new object. faculty still points to the same. # object it used to point to, but that object has mutated. # . append(x): given a new value x, add x to the end of the list. faculty. append(anthony) print(faculty) # faculty now has 5 elements, and has been mutated by appending the new value. faculty = [bo, frank, alvaro, birgit] print(faculty) # we"ve already seen this: faculty[0] = mehrdad # this might seem similar to the following code: x = 10 print(x) x = 20 print(x) # . pop(): remove the last item in the list faculty. pop() print(faculty) # . pop(i): remove the item at index i faculty. pop(0) print(faculty) # that might look like mutation, because x changed from 10 to 20 but it"s.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents