Intro To Lists Flashcards
How do you create a list?
Square brackets [ ]
Every item in a list is a (blank), so each should be enclosed with a (blank)
Python string
Quotation mark
Name 3 things a “[ ]” will make it easier to do.
- Get an item at a specified position (1st, 2nd, 3rd etc)
- Check the number of items
- Add/remove items
How would you count the number of entries in a list?
len()
Referring to any item in the list according to its position in the list is called what?
Indexing
How would you pull the first entry in a list?
[0]
How would you pull the second entry in a list?
[1]
How would you pull the last entry in a list?
Use one less than the length of the list
(e.g if the length of list is 10, index using 9)
How would you print multiple strings in Python with a single command?
Separate them with a comma
Pulling a segment of list is called?
Slicing
To pull the first 3 items in a list what would you use?
[ :3]
If you wanted the last 4 items in a list what would you use?
[-4: ]
How would you remove an item from a list?
.remove()
How would you add an item to a list?
.append()
What does this tell you?
print(“blank:” , sum(hardcover_sales[ :5]) /5)
You want to take the hardcover sales in first five days and divide it by 5