Lists in Python:

 

Lists are arbitrary collections of objects that can be nested. They are created by enclosing the comma separated items in square brackets. As strings they can be indexed and sliced, but as opposite to strings, it is also possible to modify them.

 

Example 1:

 

family = [‘yana’, ‘guy’, ‘yael’, ‘michal’]

print (family)

i = 0

while ( i < 4):

            print( family [ i ])

            i = i + 1

family.insert (4, ‘bony’)

print (family)

family.sort ( )

print (family)

family.insert(0, len(family))

print (family)

 

Example 2:

 

i = 0

num_list = []

 

while ( i < 10 ):

            num_list.insert ( i, ( i + 10) % 4)

            i = i + 1

 

print (num_list)

num_list.sort ( )

print (num_list)