List Manipulation

Total Post:113


 350  View(s)
Rate this:

Explain the list manipulation in python with example ?

  1. Re: List Manipulation

    List manipulation in Python :

    List is one of the simplest data structures in Python.Its very important and Lists are enclosed in square brackets [ ]. each item is separated by a comma.Every List item assign unique index no. A list is mutable, meaning you can change its contents. Lists have many built-in control functions. 

    Methods of List objects are: 


    L = ['yellow', 'red', 'blue', 'green', 'black'] 

    print L :

    ['yellow', 'red', 'blue', 'green', 'black'] 

    Accessing/Indexing : 

    L[0]  = 'yellow' 


    L[1:4]  = ['red', 'blue', 'green'] 
    L[2:]   = ['blue', 'green', 'black']
    L[:2] =  ['yellow', 'red']
    L[-1] =  'black'
    L[1:-1] = ['red', 'blue', 'green']

    Lengthof items in list :

    len(L)  =  5 

    Sorting the list :

    sorted(L) = ['black', 'blue', 'green', 'red', 'yellow'] 

    Append to end of list: 



Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.