⊗pyPmLsERD 50 of 208 menu

Removing elements from a list using the del operator in Python

Using the del operator, you can remove an element from a list by its index:

lst = [1, 2, 3] del lst[0] print(lst) # [2, 3]

After applying the del operator, all elements following the deleted one are shifted forward to take its place. In doing so, the length of the list itself becomes shorter by 1.

Given a list:

lst = ['a', 'b', 'c', 'd', 'e']

Remove the element with number 1.

Given a list:

lst = ['a', 1, 'b', 2, 'c', 3]

Leave only string elements in the list.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline