Python: Learn the Basics FAST From Python Programming Experts (2015)

Chapter 6: More Information Regarding Python Lists

Chapter 6: More Information Regarding Python Lists

A list is a type of data that can be written as a group of items separated by commas. The objects included in a list do not have to be of the same data type. It is considered as the most versatile variable type in Python. 

To create a list, you just have to collect values (separated by commas) and place them inside a pair of square brackets. Just like a string index, indices for Python lists begin at 0. They can also be linked, sliced, etc.

How to Access Values inside a List

If you want to access values you placed in a list, then slice the value that you need using the square brackets. When properly executed, the command will produce the information you need.

How to Update Lists

If you want to add new elements into an existing list, place the slicer (the brackets) on the left side of your operator. Afterwards, use the append () technique to add the variables.

You have two options when deleting elements from a list: (1) execute the del statement (use this if you know the specific elements that you want to remove), or (2) use the remove () technique (this is useful if you still do not know the elements to be deleted).