8 of 151 menu

The clear method

The clear method removes all elements from the list. We do not specify anything in the method parameter.

Syntax

list.clear()

Example

Let's remove all the items in our list:

lst = ['a', 'b', 'c'] lst.clear() print(lst)

Result of code execution:

[]

Example

Now let's apply the clear method to an empty list:

lst = [] lst.clear() print(lst)

After executing the code, the method will also return us an empty list:

[]

See also

  • method pop,
    which removes an element by its index
  • method remove,
    which removes an element from a list
  • method append,
    which adds an element to the end of a 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