Skip to Content
流畅的Python(第2版)
book

流畅的Python(第2版)

by Luciano Ramalho
April 2023
Intermediate to advanced
769 pages
25h 16m
Chinese
Posts & Telecom Press
Content preview from 流畅的Python(第2版)
84
3
3-4:集合的其他方法
set frozenset
s.add(e)
把元素
e
添加到
s
s.clear()
删除
s
中的全部元素
s.copy()
浅拷贝
s
s.discard(e)
s
中删除元素
e
(如果存在
e
s.__iter__()
获取遍历
s
的迭代器
s.__len__()
len(s)
s.pop()
s
中删除并返回一个元素,如果
s
为空,则抛出
KeyError
s.remove(e)
s
中删除元素
e
,如果
e
不在
s
中,则抛出
KeyError
对集合功能的概述到此结束。
3.12
节将兑现
3.8
节的承诺,探讨与
frozenset
行为非常相
似的两种字典视图。
3.12
 字典视图的集合运算
.keys()
.items()
这两个
dict
方法返回的视图对象与
frozenset
极为相似,如表
3-5
所示。
3-5
frozenset
dict_keys
dict_items
实现的方法
frozenset dict_keys dict_items
说明
s.__and__(z)
s & z
s
z
的交集)
s.__rand__(z)
反向
&
运算符
s.__contains__()
e in s
s.copy()
浅拷贝
s
s.difference(it, ...)
s
和可迭代对象
it
等的差集
s.intersection(it, ...)
s
和可迭代对象
it
等的交集
s.isdisjoint(z)
s
z
不相交(没有共同元素) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python高级编程(第2版)

Python高级编程(第2版)

Posts & Telecom Press, Michał Jaworski, Tarek Ziadé
Kafka权威指南(第2版)

Kafka权威指南(第2版)

Gwen Shapira, Todd Palino, Rajini Sivaram, Krit Petty
Python贝叶斯分析(第2版)

Python贝叶斯分析(第2版)

Posts & Telecom Press, Osvaldo Martin

Publisher Resources

ISBN: 9787115612366