Removing list elements by index with del

Elements are removed using a keyword with which we have not yet become acquainted: del. The del keyword takes a single parameter which is a reference to a list element and removes it from the list, shortening the list in the process:

>>> u = "jackdaws love my big sphinx of quartz".split()
>>> u
['jackdaws', 'love', 'my', 'big', 'sphinx', 'of', 'quartz']
>>> del u[3]
>>> u
['jackdaws', 'love', 'my', 'sphinx', 'of', 'quartz']

 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset