



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 lecture notes cover the topics of slices and boolean values in the context of the cpsc 121 (fall 2012) course. The notes explain how slices return new lists, the use of the full slice operator, and list slice exercises. Additionally, the notes discuss boolean values, their significance, and python's implementation of them.
Typology: Study notes
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Today ...
Homework
Slices always return new (shallow copied) lists
list3 = [’a’, [’b’, ’c’], ’d’]
list4 = list3[1:3]
list [[’b’, ’c’], ’d’]
list4[0][1] = ’e’
list [[’b’, ’e’], ’d’]
list [’a’, [’b’, ’e’], ’d’]
This is also true of list concatenation
list5 = [1, [10, 100]]
list6 = list5 + [2]
list [1, [10, 100], 2]
list5[1][0] = 50
list [1, [50, 100]]
list [1, [50, 100], 2]
List Slice Exercises
Assume that:
my_str = "go bulldogs"
Define expressions that Use slices to generate the following strings:
What is a Boolean value?
Python has special Boolean values
type(True) <class ’bool’>
type(False) <class ’bool’>
A detail of Python bool values