How to access or update or delete values in Lists?

How to access or update or delete values in Lists?

Team Leader Asked on March 21, 2017 in PYTHON.
Add Comment
1 Answer(s)

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']
IT Head Answered on December 5, 2017.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.