python--字典

    xiaoxiao2021-03-26  30

    >>> a = {1:'one',2:'two',3:'three'} >>> a {1: 'one', 2: 'two', 3: 'three'} >>> b = a.copy() >>> b {1: 'one', 2: 'two', 3: 'three'} >>> a {1: 'one', 2: 'two', 3: 'three'} >>> id(a) 47139216 >>> id(b) 47182688 >>> c = a >>> id (c) 47139216 >>> a.clear() >>> a {} >>> b {1: 'one', 2: 'two', 3: 'three'} >>> c {} >>> >>> >>> >>> a.pop(2) Traceback (most recent call last):   File "<pyshell#80>", line 1, in <module>     a.pop(2) KeyError: 2 >>> b.pop(2) 'two' >>> b {1: 'one', 3: 'three'} >>> a.popitem() Traceback (most recent call last):   File "<pyshell#83>", line 1, in <module>     a.popitem() KeyError: 'popitem(): dictionary is empty' >>> b.popitem() (3, 'three') >>> b {1: 'one'}
    转载请注明原文地址: https://ju.6miu.com/read-661054.html

    最新回复(0)