Python – List:

Python Lists holds the data of any datatype like an array of elements and these are mutable means the possibility of changing the content or data in it.

List can be created by giving the values that are separated by commas and enclosed in square brackets. Let us see different types of value assignments to a list.

Example:

As we know the way strings can be accessed, same way Lists can be accessed. Below is example of indexing in python for your understanding again.

Example:

Accessing and slicing the elements in List

Now let us take a list which holds different datatypes and will access the elements in that list.

Example:

Checking if the Lists are mutable:

Example:

List Comprehension:

List comprehension works like iterate operations as mentioned below.

Syntax:

Example:

Adding Elements to a list:

We can add two lists as shown in the below example.

Example:

Replicating elements in Lists:

we can replicate elements in lists as shown in the below example.

Example:

Appending elements in Lists:

We can append an element to an existing list as shown in the below example.

Example: