字典


##字典

x={“吕布”,”关羽”}
type(x)
<class ‘set’>
y={“吕布”,”扣扣不”,”关羽”,”关嘻嘻”}
type(y)
<class ‘set’>
a={“吕布”:”口口布”,”关羽”:”关嘻嘻”,”刘备”:”刘宝贝”}
b=dict(吕布=”koukoubu”,刘备=”刘宝贝”)
c=dict([(“吕布”,”扣扣不”),(“关羽”,”关嘻嘻”),(“刘备”,”刘宝贝”)])
d=dict({“吕布”:”扣扣不”,”关羽”:”关嘻嘻”,”刘备”:”刘宝贝”})
e=dict({“吕布”:”扣扣不”,”关羽”:”关嘻嘻”},刘备=”刘宝贝”)
f=dict(zip([“吕布”,”关羽”,”刘备”],[“扣扣不”,”关嘻嘻”,”刘宝贝”]))
a==b==c==d==e==f
False

 

d=dict.fromkeys(“fish”)
d
{‘f’: None, ‘i’: None, ‘s’: None, ‘h’: None}
d=dict.fromkeys(“fishc”)
d
{‘f’: None, ‘i’: None, ‘s’: None, ‘h’: None, ‘c’: None}
d[‘s’]
d
{‘f’: None, ‘i’: None, ‘s’: None, ‘h’: None, ‘c’: None}
d.update({‘i’:105,’h’:104})
d
{‘f’: None, ‘i’: 105, ‘s’: None, ‘h’: 104, ‘c’: None}

 

d.pop(‘c’)
d.pop(‘f’)
items
dict_items([(‘i’, 105), (‘s’, None), (‘h’, 104)])
values
dict_values([105, None, 104])
e=d.copy()
e
{‘i’: 105, ‘s’: None, ‘h’: 104}
len(d)
3
‘c’ in d
False
‘c’ not in d
True
list(d)
[‘i’, ‘s’, ‘h’]
list(d.values())
[105, None, 104]
e=iter(d)
next(e)
‘i’
next(e)
‘s’
next(e)
‘h’

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/279875.html

(0)
上一篇 2022年8月11日
下一篇 2022年8月11日

相关推荐

发表回复

登录后才能评论