List Data-Type

In python lists, data types are similar to arrays in C. It can contain data of different types. A comma separates the values (,) and it is enclosed within square braces ( [ ] ). We can use the slice operator (:) to access the data on the list. The plus (+) operator are used to concatenate the string, and the repetition operator(*) used to multiply the strings.

Indexed items in the list:

The list items are indexed, and the first item has index [0], the second has [1], and so on. If you try to access a list index that is not available, then the IndexError will occur. Additionally, the index can only be an integer, and if you try accessing some other type, then the TypeError will occur.

The list is Ordered:

It means that there is some defined order that the list items follow and that order cannot be changed. Further, if some new items are added to the list, they add at the end of the list and nowhere in between.

The list is Changeable:

It means that the list items can be changed and manipulated. You can add, delete, sort the list items. You can manipulate the strings with the help of operators.

Identifying the length of a list:

To identify the length of a list, you must pass the len() function and fill the brackets with the list name whose length is to be determined.

Data types of list:

Python list items can contain any data type, including integers, floating value, character, strings, Boolean, etc. You can create a list with only one kind of data type or a mixture of several data types.

List constructor:

list() can also be used as a constructor while creating a list.

List Duplicates:

The list allows duplicate elements inside its square brackets.

A list can also have another list as an item which is also known as a nested list.

We can even see the type of datatype L1, L2,L3, L4

The lists are in a very ordered fashion.
The element of the list can be accessed by the respective index.
The lists consist of mutable or changeable types.
A list can be able to store the number of various elements.

How to access elements from a list?

List Index:-
We can use the index operator [ ] to access a specific item in a list. In Python, indices start their naming at 0. So, a list having 10 elements will have an index from 0 to 9. Trying to access the respective indexes other than these will also raise an IndexError. The index should be an integer that is we cannot write use float or other types, this will result in TypeError.


weblist = ["knowledge2life 1", "knowledge2life 2", "knowledge2life 3"] print(weblist)


['knowledge2life 1', 'knowledge2life 2', 'knowledge2life 3']