Home » How - To / Tutorial » Programming » Characteristic of Python Lists

Characteristic of Python Lists

R-vs-Phyton-Which-one-is-better-2 Characteristic of 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)
  2. Use the remove () technique (this is useful if you still do not know the elements to be deleted).

Leave a Reply

Your email address will not be published. Required fields are marked *

Name *
Email *