How to access or update or delete values in Lists?
How to access or update or delete values in Lists?
Share
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Aviance School is one of the largest web solutions platform in India for developers to learn and share their programming knowledge and build their careers.
A Python list is a sequence of data values called items or elements.It can be compared to arrays.You can modify the items or elements of a list as per you needed with Python. Modifying a list means to change a particular item or element, add a new item OR remove an existing item from the list.
Creating Python List
In this section you will learn how to create a Python List.
Assign an empty List
fruits = [];
Create a Python list with items or elements
To create the list fill the values in list separated by commas with square brackets.
fruits = ['mango', 'plum', 'apple', 'orange'];
Delete List Elements
fruits =['mango', 'plum', 'apple', 'orange'];
print fruits
del fruits[3];
print "After deleting value at index 3 is: "
print fruits
Output Of the program
['mango', 'plum', 'apple', 'orange']
After deleting value at index 3 is :
['mango', 'plum', 'apple']