1

I have a empty dictionary

d = {}

I have these variables:

key = "foo"
value = 1

I want to add them to dictionary as key and value variables because they can be change in a for loop. What should be the proper syntax?

JayGatsby
  • 1,541
  • 6
  • 21
  • 41

1 Answers1

14

This is short answer:

d[key] = value

print(d) # d = {"foo" : 1}

see this link for more info about Python dictionary:

tutorialpoint_dictionary

Python_data_structures

ᴀʀᴍᴀɴ
  • 4,443
  • 8
  • 37
  • 57