31 of 151 menu

The pop method

The pop method removes the first element from a set. Since there is no ordered placement of elements in the set, it is impossible to say exactly which element will be removed. We do not specify anything in the method parameter.

Syntax

set.pop()

Example

Let's remove the first element from our set:

st = {'a', 'b', 'c'} st.pop() print(st)

Result of code execution:

{'b', 'c'}

Example

Now let's perform the same operation again:

st = {'a', 'b', 'c'} st.pop() print(st)

This time after running the code we got a different result:

{'a', 'c'}

See also

  • method remove,
    which removes elements from a set
  • method discard,
    which removes elements that are in the set
  • method add,
    which adds elements to a set
  • function len,
    which returns the length of the set
  • method union,
    which unites sets
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