Lists in Python

Lists are like arrays which are used to store multiple data items in a single variable.

The List in python is created with the square brackets "[ ]".

Syntax:

listname = ['value1','value2',....,'valueN']

Example:

fundalist = ['funda','of','web','it']

To Print the list, you can directly type the listname in the print().

fundalist = ['funda','of','web','it']
print(fundalist)

Output for the above code will be :

['funda', 'of', 'web', 'it']

To print the values individually, we have to use the forloop.

fundalist = ['funda','of','web','it']

for x in fundalist:    
    print(x)


Output for the above code will be :

funda
of
web
it
Always Remember :
  • Lists are similar to array as the have index position starting from 0. When a new value is inserted in the list, it will be inserted in the n+1th index i.e. the end of the lists.
  • Lists can consists the same value more than once.
  • Lists can be altered after creating them. We can perform various operations like add new item or remove items from the list. In short, lists are changable in nature.