Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Updating Lists in python

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 603
    Comment on it

    If you want to update single or multiple elements of lists then you have to provide the slice on the left-hand side of the assignment operator, and to add to elements in a list you can use the append() method. For example

    #!/usr/bin/python
    
    list = ['physics', 'chemistry', 1997, 2000];
    
    print "Value available at index 2 : "
    print list[2]
    list[2] = 2001;
    print "New value available at index 2 : "
    print list[2]

    Output will be
    Value available at index 2 :
    1997
    New value available at index 2 : 2001

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: