21 of 151 menu

The keys method

The keys method returns the dictionary keys. The keys are returned as a special object dict_keys. We do not specify anything in the method parameter.

Syntax

dictionary.keys()

Example

Let's find all the keys in our dictionary:

dct = { 'a': 1, 'b': 2, 'c': 3 } print(dct.keys())

Result of code execution:

dict_keys(['a', 'b', 'c'])

Example

Let's get the keys as a list:

dct = { 'a': 1, 'b': 2, 'c': 3 } print(list(dct.keys()))

Result of code execution:

['a', 'b', 'c']

See also

  • method items,
    which returns the keys and values ​​of a dictionary
  • method values,
    which returns all the values ​​of the dictionary
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