Technology Programming

How to Use a Python Dictionary

    • 1). Type the following in your Python program: D = {"k1":"string", "k2":123}. Instead of "string" and 123, you can use any value you would like. Strings, integers and other dictionary variables will all work.

    • 2). Type the following to modify one of the values in your dictionary: D{"k1"} = "different". Once again, you can use any value you would like to replace the existing value. This will create a new key-value pair.

    • 3). Type the following to delete a key-value pair from your dictionary: del D{"k1"}.

Leave a reply