CS 115 Lecture Lists Part 1 Taken from notes by

CS 115 Lecture Lists Part 1 Taken from notes by
1 / 1
CS 115 Lecture Lists Part 1 Taken from notes by - slide 1 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 2 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 3 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 4 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 5 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 6 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 7 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 8 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 9 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 10 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 11 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 12 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 13 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 14 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 15 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 16 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 17 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 18 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 19 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 20 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 21 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 22 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 23 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 24 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 25 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 26 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 27 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 28 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 29 of 30 CS 115 Lecture Lists Part 1 Taken from notes by - slide 30 of 30
CS 115 Lecture Lists Part 1 Taken from notes by Dr. Neil Moore Lists In Python, a string is a sequence of characters, but there are other kinds of sequences too. The most important is the list. A list is, like a string, a sequence of

Related Topics

Download this presentation From Below

"CS 115 Lecture Lists Part 1 Taken from notes by" is the property of its rightful owner. Permission is granted to download and print the materials on this website for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.

Presentation Transcript

01
CS 115 Lecture Lists Part 1
Taken from notes by Dr. Neil Moore<br>
02
Lists In Python, a string is a sequence of characters, but there are other kinds of sequences too. The most important is the list.
A list is, like a string, a sequence of things.
But unlike a string, the things can be any type:
List of numbers: [7, 1, 3]
List of strings: [“hello”, “world”]
Even lists of lists: [[1,2,3], [4,5,6], [7,8], [True]]<br>
03
List syntax To write a literal list in your program, use the square brackets:
physicists = [“Einstein”, “Newton”, “Hawking”]
The things in a list are called its elements.
This list has 3 elements, each one a string
Its length is 3 (the number of elements)
You can use len to get the length:
print(len(physicists)) # gives 3 (an integer)
Elements are numbered starting from zero
As with strings, we call this the position or index of the element
Lists can be concatenated with the + operator:
print([3, 1, 4] + [1, 5, 9]) gives [3, 1, 4, 1, 5, 9]
But only with other lists! [3, 1, 4] + 1 gives TypeError!<br>