Answer the question
In order to leave comments, you need to log in
How to understand the behavior of a dictionary?
There is a dictionary created manually
dch = {0:'0', 1:'1', 2:'2', 3:'3', 4:'4', 5:'5', 6:'6', 7:'7', 8:'8', 9:'9'}
dch2 = {x: str(x) for x in range(10)}
>>> type(dch)
<class 'dict'>
>>> type(dch2)
<class 'dict'>
>>> type(dch[5])
<class 'str'>
>>> type(dch2[5])
<class 'str'>
>>> dch[5]
'5'
>>> dch2[5]
'5'
>>> dch[5] is '5'
True
>>> dch2[5] is '5'
False
>>> dch2[10] = '10'
>>> dch2[10] is '10'
True
>>> dch2[9] is '9'
False
>>>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question