CH3 - Introducing Lists Flashcards
(29 cards)
What is a List?
A collection of items in a particular order.
What symbol represents a list in Python?
Square brackets [ ].
How to name a List?
Using plurals, for example: (Names)
How are elements separated in a List?
By using commas.
How is the position counted within a List?
Index.
Start of an Index?
0.
Last element of the index?
-1, or last positive index count.
Are methods supported in Lists?
Yes.
Are F-strings supported in Lists?
Yes.
Are List dynamic or static?
Dynamic.
How to replace elements in a list?
Index position, and value.
What is .append()?
A method in Python, That adds elements to the end of the list.
What is .insert()?
A method in Python, That inserts elements to any position of the list.
What is a simple way to add an element to a list?
By using the .append() method.
How to add an element to the end of a list?
By using the .append() method.
How to remove an element from the list using index position?
By using a del statement.
Does the del statement remove elements temporally or permanently?
permanently.
What is .pop()?
A method in Python that removes the last element from the list.
What is .pop(3)?
A method in Python that removes the 4th element from the list.
What is .remove(‘jim’)?
A method in Python that removes the ‘jim’ element from the list.
What happens when they are multiple elements with the same value in a list, and the .remove() method is used?
Only the 1st occurrence of the value is deleted.
What is .sort()?
A method in Python, That changes the order of the list alphabetically.
Does the .sort() method change the elements temporally or permanently?
permanently.
What is reverse = True?
A Python argument you can pass to the .sort() method to change the list in alphabetical order.