Lists
Lists in Python
my_list = [1,2,3,4,5]
print(type(my_list))
# prints listWhat you can do with lists:
You can
popout the last element of the list (by default) - (pop method)
my_list.pop()
# This is a mutable object
# Since it is a mutable object you don't have to reassign it to itself
# i.e my_list = my_list.pop()
# It will print the list: [1,2,3,4]
# To pop out the first value:
my_list.pop(0)
# If you capture the retured value
sentence = my_list.pop()
print(my_list) # This will still be the appended list
print(sentence) # But the poped item is stored in this variable2. Changing a value in the list:
3. List can contain a list:
4. Appending lists (append method)
5. Sorting through lists (sort method)
6. Reverse through lists (reverse method)
These don't have to be integer, python is smart enough to sort strings as well
7. Slicing Lists
First value in slicing is inclusive, last value is non-inclusive
8. The len function
8. Merging lists together
Last updated