-2

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,441
  • 5
  • 20
  • 39

1 Answers1

12

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,231
  • 7
  • 33
  • 53