January 2019
Beginner
318 pages
8h 23m
English
To remove a list element, you can use either the del statement if you know exactly which element(s) you are deleting. You can use the remove() method if you do not know exactly which items to delete. Refer to the following example:
#!/usr/bin/python3cities = ['Mumbai', 'Bangalore', 'Chennai', 'Pune']print ("Before deleting: ", cities)del cities[2]print ("After deleting: ", cities)Output:Before deleting: ['Mumbai', 'Bangalore', 'Chennai', 'Pune']After deleting: ['Mumbai', 'Bangalore', 'Pune']
Read now
Unlock full access