
- Python 3 Basic Tutorial
- Python 3 - Home
- What is New in Python 3
- Python 3 - Overview
- Python 3 - Environment Setup
- Python 3 - Basic Syntax
- Python 3 - Variable Types
- Python 3 - Basic Operators
- Python 3 - Decision Making
- Python 3 - Loops
- Python 3 - Numbers
- Python 3 - Strings
- Python 3 - Lists
- Python 3 - Tuples
- Python 3 - Dictionary
- Python 3 - Date & Time
- Python 3 - Functions
- Python 3 - Modules
- Python 3 - Files I/O
- Python 3 - Exceptions
Updating Lists in Python
You can update single or multiple elements of lists by giving the slice on the left-hand side of the assignment operator, and you can add to elements in a list with the append() method.
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]
Note − append() method is discussed in subsequent section.
Output
When the above code is executed, it produces the following result −
Value available at index 2 : 1997 New value available at index 2 : 2001
- Related Articles
- Updating Strings in Python
- Updating Tuples in Python
- Updating Dictionary in Python
- Multi-dimensional lists in Python
- Dividing two lists in Python
- Sort lists in tuple in Python
- Accessing Values of Lists in Python
- Merge Two Sorted Lists in Python
- Merge k Sorted Lists in Python
- Combining two sorted lists in Python
- Unpacking tuple of lists in Python
- Updating data in MongoDB
- How do we define lists in Python?
- Intersection of Two Linked Lists in Python
- Concatenate two lists element-wise in Python

Advertisements