Computer Science 1026A/B Lecture Notes - Lecture 6: Linear Search, Inverse Function, The Confusion

21 views21 pages
terubarenuka and 39895 others unlocked
COMPSCI 1026A/B Full Course Notes
26
COMPSCI 1026A/B Full Course Notes
Verified Note
26 documents

Document Summary

: def: a list is a container that stores a sequence of values. Each element that is stored is given an index value/position. To access a list element, you specify which index you want to use. That is done with the subscript operator ([]) in the same way that you access individual characters in a string. # 1: creating a list values = [32, 54, 67. 5, 29, 35, 80, 115, 44. 5, 100, 65] # 3: replacing a list element values[4]= 87. :lists and strings are both sequences, so the [] operator can be used to access an element for any sequence. :the most common error in using lists is accessing a nonexistent element values = [2. 3, 4. 5, 7. 2, 1. 0, 12. 2, 9. 0, 15. 2, 0. 5] values[8] = # error values has 8 elements. :we can use the len() function to determine the number of element in a list print (len(values)) 8. : values[4] accessing the element positioned at the 4th position.

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