List in Python Part 1
A list is a data type that can hold more than one value. Some important properties about list include:
- Lists are ordered
- They can contain mixed types of object, for example: floats, string, intergers ect
- List are mutable and dynamics
- List is ordered by index starting with zero
Here is what a list would look like in python 3
>>> fruit = ['apple', 'berry', 'grapes']
>>> fruit
['apple', 'berry', 'grapes']
>>>
You can add, remove items or elements to a list. This makes list dynamic. Here is a example of how to do it by using the built-in methods to add and remove more item from fruit list.
>>> fruit.append('banana')
>>> fruit
['apple', 'berry', 'grapes', 'banana']
>>>
Append is used to add a object however you cannot place the item where you want it to be, if you want to place your object you can use the method insert.
>>> fruit.insert(1, 'orange')
>>> fruit
['apple', 'orange', 'berry', 'grapes', 'banana']
>>>
If you are wondering why I put 1 when the orange is the second item the reason is that the item is listed from 0 to any number this is called index.