DevNet Associate DEVASC 200-901 Official Certification Guide by Adrian Iliesiu (z-lib.org)

(andrew) #1
list.copy(
alist)

Returns a copy of the list

list.coun
t(elemen
t)

Shows the number of elements with the
specified value

list.exten
d(alist)

Adds the elements of a list to the end of the
current list

list.inde
x()

Returns the index number of the first element
with a specified value

list.inser
t( index,
element)

Adds an element at a specified index value

list.pop(i
ndex)

Removes an element at a specific index
position, or if no index position is provided,
removes the last item from the list

list.remo
ve()

Removes a list item with a specified value

list.rever
se()

Reverses the list order

list.sort(
)

Sorts the list alphabetically and/or numerically

Tuples


Tuples and lists are very similar. The biggest difference
between the two comes down to mutability. As discussed
earlier, Python data types are either mutable or
immutable. Lists are mutable, and tuples are immutable.
So why would you need these two types if they are so
similar? It all comes down to how Python accesses
objects and data in memory. When you have a lot of
changes occurring, a mutable data structure is preferred

Free download pdf