The inbuilt dict()
function in Python is used to construct dictionaries.
Dictionaries are data types within Python that exist as key:value pairs.
dict(**kwarg)
dict([mapping, **kwarg])
dict([iterable, **kwarg])
Dictionaries can be created with the following methods.
postcodes = dict(griffith=2603, belconnen=2617, phillip=2606)print("Canberra postcodes: ", postcodes)
postcodes_cbr = dict({'griffith':2603, 'belconnen':2617, 'phillip':2606})print("Canberra postcodes: ", postcodes_cbr)#Passing an optional keyword argumentpostcodes_syd = dict({'sydney':2000, 'campbeltown':2560}, casula=2170)print("Sydney postcodes: ", postcodes_syd)
postcodes_cbr = dict([('griffith', 2603), ('belconnen', 2617)])print("Canberra postcodes: ", postcodes_cbr)#Passing an optional keyword argumentpostcodes_syd = dict([('sydney',2000), ('campbeltown',2560)], casula=2170)print("Sydney postcodes: ", postcodes_syd)