List in Python

List: In Python, a list is created by placing all the items inside a square bracket [ ], and are separated by commas.

It can contain a number of items and they may be of different types (integer, float, string etc.).lists are very similar to arrays in java programming. It can contain any type of variable, and they can contain as many variables as per the requirement of users. lists can also be iterated over in a very simple manner.

Example

demolist = []

demolist.append(1)

demolist.append(2)

demolist.append(3)

print(demolist[0])

print(demolist[1])

print(demolist[2])

# demolist retrun 1,2,3.

for x in demolist:

print(x)

Examle:

# empty list

List1 = []

# list of integers

List2 = [1, 2, 3]

print(List2)

# list with mixed datatypes

List3 = [1, “Hi”, 4.4]

print(List3)

Leave a Reply

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