lists
TRANSCRIPT
[ lists ]
Defining Lists
* First, you define a list of five elements. Note that they retain their original order. This is not an accident. A listis an ordered set of elements enclosed in square brackets.** A list can be used like a zero−based array. The first element of any non−empty list is always names [0].*** The last element of this five−element list is names [4], because lists are always zero−based.
Negative List Indices
Slicing a List
Slicing Shorthand
* If the left slice index is 0, you can leave it out, and 0 is implied. So colours[:3] is the same as colours[0:3]** Similarly, if the right slice index is the length of the list, you can leave it out. So colours[3:] is the same as colours[3:5], because this list has five elements.
Adding Elements to Lists
.append
.insert
.extend
append adds a single element to the end of the list.
insert inserts a single element into a list.
extend concatenates lists.
example
THE DIFFERENCE BETWEEN EXTEND AND APPEND
By \ salma subh
GOOD LUKE