



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
These are lecture notes for cpsc 121 (fall 2012) covering the topic of lists, a new data type in python. Lists are a sequence of values, and can contain values of any types, including other lists. They are represented using []’s and are mutable, meaning their values can be changed. The index operator is used to access and modify elements in a list.
Typology: Study notes
1 / 6
This page cannot be seen from the preview
Don't miss anything!




Today ...
Reading
HW
Reminders
Consider this code snippet z = 10 def f(x, y, z): tmp = x + y // z return tmp What is the result of the following statements?
(a) tmp = 40 z = 30 is printed (b) tmp = 40 z = 10 is printed (c) Syntax error (d) None of the above
The index (aka subscript) operator
listvar[index]
the list = [10, 20, 30]
first elem = the list[0] print(first elem)
10
Subscripts can be used to change list values
the list[0] = 15
print(the list)
[15, 20, 30]
The type of a list ...
the_list = [2, 4, 6] type(the_list) <class ’list’>
the_list = [’s’, ’p’, ’a’, ’m’] type(the_list) <class ’list’>