What is the syntax to update a list?

#to update the value of one element from the list
<list name>[<index>] = <new value>

#to update multiple elements' values from the list
<list name>[<start index, inclusive>:<end index, exclusive>] = [<new values>]
#to add one more element to an existing list
<list name>.append(<value to be added>)

#to create a new updated list from an old list + new elements
<new list name> = <old list name> + [<value1>, <value2>,...etc]
#examples
>>> grades=[60,77,86,95]

>>> grades
[60, 77, 86, 95]

>>> grades.append(100)
>>> grades
[60, 77, 86, 95, 100]

>>> updatedGrades = grades+[54,34,64]
>>> updatedGrades
[60, 77, 86, 95, 100, 54, 34, 64]

>>> updatedGrades[0] = 0
>>> updatedGrades
[0, 77, 86, 95, 100, 54, 34, 64]

>>> updatedGrades[:2] = [100,100]
>>> updatedGrades
[100, 100, 86, 95, 100, 54, 34, 64]

 

 

Advertisements