Stats

548 Contributors: 36
2017-03-06
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook

Dictionary

Download python eBook

Syntax

  • mydict = {}
  • mydict[k] = value
  • value = mydict[k]
  • value = mydict.get(k)
  • value = mydict.get(k, "default_value")

Parameters

ParameterDetails
keyThe desired key to lookup
valueThe value to set or return

Remarks

Helpful items to remember when creating a dictionary:

  • Every key must be unique (otherwise it will be overridden)
  • Every key must be hashable (can use the hash function to hash it; otherwise TypeError will be thrown)
  • There is no particular order for the keys.

Related Examples