in Python by

1 Answer

0 votes

List in python is implemented to store the sequence of various type of data. However, python contains six data types that are capable to store the sequences but the most common and reliable type is list.

A list can be defined as a collection of values or items of different types. The items in the list are separated with the comma (,) and enclosed with the square brackets [].

A list can be defined as follows.

  1. L1 = ["John"102"USA"]  
  2. L2 = [123456]  
  3. L3 = [1"Ryan"]  

List indexing and splitting

The indexing are processed in the same way as it happens with the strings. The elements of the list can be accessed by using the slice operator [].

The index starts from 0 and goes to length - 1. The first element of the list is stored at the 0th index, the second element of the list is stored at the 1st index, and so on.

Consider the following example.

Python Lists

Unlike other languages, python provides us the flexibility to use the negative indexing also. The negative indices are counted from the right. The last element (right most) of the list has the index -1, its adjacent left element is present at the index -2 and so on until the left most element is encountered.

Python Lists

Updating List values

Related questions

0 votes
asked Jun 12, 2020 in Python by Robindeniel
0 votes
asked Aug 30, 2020 in Python by sharadyadav1986
0 votes
asked May 17, 2020 in Python by sharadyadav1986