Reputation: 21
dict = {}
dict['key' : 'value']
print(dict)
Upvotes: 1
Views: 3292
Reputation: 303
You can't add like this, it's a dictionary that takes key and value as a separate entity like
dict['key'] = 'value'
After doing this, the dictionary will automatically convert itself like-
dict['key' : 'value']
Upvotes: 0
Reputation: 328
well you can do much more d={} for appending to it you can do
d={'key1':'value1','key2':'value'}
also
d.update(key3:'val3')
hope this helps
Upvotes: 0
Reputation: 687
dict = {}
dict['key'] = 'value'
print(dict)
[index1 :index2 ]
is list slice operation, which will not work on dict
Upvotes: 2