abc = {} abc[int: anotherint]
Then an error occurred. TypeError: non-writable type? Why did I get this? I tried str ()
This seems to be a syntax issue:
>>> abc = {} >>> abc[1] = 2 >>> abc {1: 2} >>> abc = {1:2, 3:4} >>> abc {1: 2, 3: 4} >>>
At least the syntax of the following is incorrect
abc[int: anotherint]
I think you want to say
abc = [int: anotherint]
This is not true. The right way -
abc = {int: anotherint}
if abcalready defined in this case:
abc
abc[int] = anotherint
is also a valid option.
: - , , int (, [. ]) anotherInt. , python, , , .
-, x [{int: anotherInt}]:
, , , , python , - , ... :
x={} x[x]=1
, , , 1?
x[{}] x[{x:x}] x[{{}:x}] x[x]
, {} != {} ,
{} != {}
Since the title says add, and none of the answers gave a solution to add things to the dictionary, I give it a try:
abc = {} abc[1]= 2 abc['a'] = [3,9,27] ==> a = {1:2, 'a':[3,9,27]}