---
# System prepended metadata

title: 'Lists in Python Programming Language: Week 7 at Blockfuse Labs.'

---

# Lists in Python Programming Language: Week 7 at Blockfuse Labs. 

A list is an inbuilt data structure in python programming language that allows the storage of multiple items in a single variable. These items can be integers, strings, boolean or, they can even be lists or dictionaries in another list. This means that a list can contain up to two ore more dictionaries, and these dictionaries will contain multiple items or values. 

Lists are ordered, items in a list are stored in a specific order. They are also mutable, you can always edit a list by adding and removing items. Items in a list can be accessed using index numbers, and indexing in lists start from 0. it is important to note that in a list, there can be duplicates. Items can appear more than once. 

Below is an example of how to create a list. 

#### The syntax is : 
`myllist =  [item1,item2,item3,item4,item5] `

For example, let’s create a list of our my favourite car brands;

`my_fav_cars = [“Honda”,”Mercedez”,”IVM”,”BMW”] `
The list above is held in a variable named ‘my_fav_cars’ and the list holds up to four items. 

We can also create a list of my favourite numbers, let’s say you are a football fan and you want to list jersey numbers of your best players. 

`my_fav_players = [ 7, 10, 8, 9]`
If you pay attention, I did not use the quotation marks here, so that implies that when dealing with numbers, it is needless to use the quotation marks. 

Let’s also create a mixed list that contains strings, integers, boolean and float data. 
`my_mixed_list = [“learn”, 1000, True, 5.24]`
you can now see that lists can contain mixed data too. But that is not all. A list can be empty. 

empty_list = [] 
As you can see, the above list does not contain anything inside of it. 

#### To access an item in a list, let’s say in my_fav_cars, using indexing, you can do that as I show below; 
You use the ‘print’ function to concatenate it. 
```
print(my_fav_cars[0]) 
print(my_fav_cars[-1]) 
```
The first line prints out “Honda” because it is indexed 0 while the second line prints out “BMW”. 

To modify items in a list, you use the following method; 
```
my_fav_cars[0] = “Toyota” 
print(my_fav_cars) 
```

This code will now output Toyota in the position of Honda. 

#### To add items to a list, you can achieve that using several methods. I will walk you through them. 
First, the .append(); this adds an item to the end of a list. So if we do something like; 
`my_fav_cars.append(“Lexus”)`
It will add Lexus to the end of the list. 

If we use the insert() method, it adds an item to a specific position. 
my_fav_cars.insert(0, “Renault”)
This replaces the first item in the list by moving the first item to the next position.

Lastly, if we use the extend(), it allows the addition of multiple items. For example; 
`my_fav_cars.extend([“Buggati”, “Chevron”])`
As you can guess, it adds Buggati and Chevron to our  existing favourite cars list. 

#### You can also remove items from a list. The methods below are used to remove items in a list. 
Removing by value; 
`my_fav_cars.remove(“Toyota”)`
`my_fav_cars.pop(0)`
`del my_fav_cars[0]`
`my_fav_cars.clear`
All these methods can be used depending on the programmer’s need. 

My week seven(7) was a good week, I progressed and my python programming skill also added new value. Week eight(8) is here and I excited already to share my experience after the week. 

Thank you for stopping by, see you in my next update. 

