Python Lists
Creating a List
fruits = ['apple', 'banana', 'orange', 'mango']
print(fruits)Accessing List items
fruits = ['apple', 'banana', 'orange', 'mango']
first_fruit = fruits[0]
print(first_fruit)fruits = ['apple', 'banana', 'orange', 'mango']
last_fruit = fruits[-1]
next_to_last_fruit = fruits[-2]
print(last_fruit)
print(next_to_last_fruid)Append item to a List
Insert item in List
Removing items from a list
Removing the last item from the list using .pop
.popRemoving items using the item index & the delete keyword del list[index]
del list[index]Removing items using the value of the item list.remove(value)
list.remove(value)Finding the index of an element in a list
Sorting a python list
Slicing a list in python
Unpacking a list in python
Looping through a python list
Python List Comprehension
Last updated