004 Python-Data-Structures-Lists
004 Python-Data-Structures-Lists
• What is .append?
• It is a method for that object.
• Using object.the_thing() is a way we can invoke that.
Operations on Lists : concatenation
• What if we have two lists of numbers
• We can concatenate two lists together.
fave_n = [2, 3, 5, 7, 11]
rob_faves = [1,6,4,3,8]
our_faves = fave_n + rob_faves
#→ [ 2, 3, 5, 7, 11, 1, 6, 4, 3, 8 ]
# fave_n and rob_faves are unchanged!
fave_n.extend(rob_faves)
# Mutates fave_n by attaching 1, 6, 4, 3, 8
Operations on Lists : del, pop & remove
• Deleting items at specific indices with del()
fave_n = [2, 3, 5, 7, 11]
del(fave_n[2]) → [2,3,7,11]
• Remove element at the end with .pop(), will return the removed element.
removed_item = fave_n.pop()
print(removed_item) → 11