Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
>>> d = dict()
>>> d
{}
>>> type(d)
<class 'dict'>
>>>
>>> d = 1
>>> d
1
>>> d = {}
>>> d
{}
>>> type(d)
<class 'dict'>
>>>
>>> d = {0:"a",1:"b",2:"c",3:"d"}
>>> d
{0: 'a', 1: 'b', 2: 'c', 3: 'd'}
>>> 0 in d
True
>>> 3 in d
True
>>> 4 in d
False
>>> -1 in d
False
>>> "a" in d
False
>>> "0" in d
False
>>>
>>>
>>> d
{0: 'a', 1: 'b', 2: 'c', 3: 'd'}
>>> del d[0]
>>> d
{1: 'b', 2: 'c', 3: 'd'}
>>> d[0]
Traceback (most recent call last):
File "<pyshell#24>", line 1, in <module>
d[0]
KeyError: 0
>>> d[4]
Traceback (most recent call last):
File "<pyshell#25>", line 1, in <module>
d[4]
KeyError: 4
>>> d
{1: 'b', 2: 'c', 3: 'd'}
>>> del d['d']
Traceback (most recent call last):
File "<pyshell#27>", line 1, in <module>
del d['d']
KeyError: 'd'
>>> d
{1: 'b', 2: 'c', 3: 'd'}
>>> del d[3]
>>> d
{1: 'b', 2: 'c'}
>>>
>>>
>>> d = {0:"a",1:"b",2:"c",3:"d"}
>>> d
{0: 'a', 1: 'b', 2: 'c', 3: 'd'}
>>> d.clear()
>>> d
{}
>>> d = {0:"a",1:"b",2:"c",3:"d"}
>>> d
{0: 'a', 1: 'b', 2: 'c', 3: 'd'}
>>> d.popitem()
(3, 'd')
>>> d
{0: 'a', 1: 'b', 2: 'c'}
>>> item = d.popitem()
>>> d
{0: 'a', 1: 'b'}
>>> item
(2, 'c')
>>>
>>>
>>> d = {0:"a",1:"b",2:"c",3:"d"}
>>> d
{0: 'a', 1: 'b', 2: 'c', 3: 'd'}
>>> d.pop(1,'XXX')
'b'
>>> d
{0: 'a', 2: 'c', 3: 'd'}
>>> d.pop(1,'XXX')
'XXX'
>>> d
{0: 'a', 2: 'c', 3: 'd'}
>>> d.pop(5,'XXX')
'XXX'
>>> d
{0: 'a', 2: 'c', 3: 'd'}
>>> d.pop(0)
'a'
>>> d
{2: 'c', 3: 'd'}
>>> d.pop(0)
Traceback (most recent call last):
File "<pyshell#56>", line 1, in <module>
d.pop(0)
KeyError: 0
>>> d.pop(4)
Traceback (most recent call last):
File "<pyshell#57>", line 1, in <module>
d.pop(4)
KeyError: 4
>>>
>>> d = {0:"a",1:"b",2:"c",3:"d"}
>>> d
{0: 'a', 1: 'b', 2: 'c', 3: 'd'}
>>> d.get(0)
'a'
>>> d
{0: 'a', 1: 'b', 2: 'c', 3: 'd'}
>>> d.get(4)
>>> d
{0: 'a', 1: 'b', 2: 'c', 3: 'd'}
>>> d.get(0,"XXX")
'a'
>>> d.get(4,"XXX")
'XXX'
>>> d.get(4)
>>>
>>> print(d.get(4))
None
>>>
>>>
>>> d = {0:"a",1:"b",2:"c",3:"d"}
>>> d
{0: 'a', 1: 'b', 2: 'c', 3: 'd'}
>>> d.items()
dict_items([(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd')])
>>> d.values()
dict_values(['a', 'b', 'c', 'd'])
>>> d.keys()
dict_keys([0, 1, 2, 3])
>>>
>>>
>>>
|