Python Dictionary constructor initialized with keyword argument list

Overview:

  • A Python dictionary object with values popualated onto it can be created by calling the constructor dict() with keyword arguments.
  • Each keyword argument becomes a key of type string in the newly created dictionary and the value of the keyword argument becomes the value of the key.

Example:

#Example Python program that creates
#a dictionary by calling the dict constructor
#with keyword arguments
langVsAuthor = dict(CPlusPlus = "BjarneStroustrup",
                    Python = "GuidovanRossum",  
                    Fortran = "JohnWBackus");
print("Programming languages and their authors:");
print(langVsAuthor);

 Output:

Programming languages and their authors:
{'CPlusPlus': 'BjarneStroustrup', 'Python': 'GuidovanRossum', 'Fortran': 'JohnWBackus'}

 


Copyright 2024 © pythontic.com