# in 操作if2in sc:
print(2222222)
if23in sc:
print(nonononono)
for i in sc:
print(i)
2222222
1
2
3
4
43
12
11
54
# 集合的另一种遍历
sa = {(1,2,3),(4,5,6),("i","love","wangxiaojing")}
for i,j,k in sa:
print(i,j,k)
i love wangxiaojing
456123
# 集合的生成式
sa = {1,2,3,4,5,6,7,8,9,10}
# 利用sa生成一个sb
sb = {i for i in sa}
print(sb)
sc = {i for i in sa if i % 2 == 0}
print(sc)
# 双重for循环# 把sa中的每一个元素的平方生成一个新的集合# 1. 用一个for
sd = {i**2for i in sa}
print(sd)
# 2. 使用两个for
se = { m*n for m in sa for n in sa}
print(se)
Help on class setinmodule builtins:
class set(object)
|set() ->newemptyset object
|set(iterable) ->newset object
|| Build an unordered collection ofunique elements.
|| Methods defined here:
|| __and__(self, value, /)
|Return self&value.
|| __contains__(...)
| x.__contains__(y) <==> y in x.
|| __eq__(self, value, /)
|Return self==value.
|| __ge__(self, value, /)
|Return self>=value.
|| __getattribute__(self, name, /)
|Return getattr(self, name).
|| __gt__(self, value, /)
|Return self>value.
|| __iand__(self, value, /)
|Return self&=value.
|| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|| __ior__(self, value, /)
|Return self|=value.
|| __isub__(self, value, /)
|Return self-=value.
|| __iter__(self, /)
| Implement iter(self).
|| __ixor__(self, value, /)
|Return self^=value.
|| __le__(self, value, /)
|Return self<=value.
|| __len__(self, /)
|Return len(self).
|| __lt__(self, value, /)
|Return self<value.
|| __ne__(self, value, /)
|Return self!=value.
|| __or__(self, value, /)
|Return self|value.
|| __rand__(self, value, /)
|Returnvalue&self.
|| __reduce__(...)
|Return state information for pickling.
|| __repr__(self, /)
|Return repr(self).
|| __ror__(self, value, /)
|Returnvalue|self.
|| __rsub__(self, value, /)
|Returnvalue-self.
|| __rxor__(self, value, /)
|Returnvalue^self.
|| __sizeof__(...)
| S.__sizeof__() -> size of S in memory, in bytes
|| __sub__(self, value, /)
|Return self-value.
|| __xor__(self, value, /)
|Return self^value.
||add(...)
|Add an element to a set.
|| This has no effect if the element is already present.
|| clear(...)
| Remove all elements from this set.
||copy(...)
|Return a shallow copyof a set.
|| difference(...)
|Return the difference of two or more sets as a new set.
|| (i.e. all elements that arein this set but not the others.)
|| difference_update(...)
| Remove all elements of another setfrom this set.
|| discard(...)
| Remove an element from a set if it is a member.
|| If the element isnot a member, do nothing.
||intersection(...)
|Return the intersectionof two sets as a new set.
|| (i.e. all elements that areinboth sets.)
|| intersection_update(...)
|Update a setwith the intersectionof itself and another.
|| isdisjoint(...)
|ReturnTrue if two sets have a null intersection.
|| issubset(...)
| Report whether another setcontains this set.
|| issuperset(...)
| Report whether this setcontains another set.
|| pop(...)
| Remove andreturn an arbitrary set element.
| Raises KeyError if the setis empty.
|| remove(...)
| Remove an element from a set; it must be a member.
|| If the element isnot a member, raise a KeyError.
|| symmetric_difference(...)
|Return the symmetric difference of two sets as a new set.
|| (i.e. all elements that arein exactly oneof the sets.)
|| symmetric_difference_update(...)
|Update a setwith the symmetric difference of itself and another.
||union(...)
|Return the unionof sets as a new set.
|| (i.e. all elements that arein either set.)
||update(...)
|Update a setwith the unionof itself and others.
||----------------------------------------------------------------------|Static methods defined here:
|| __new__(*args, **kwargs) from builtins.type
|Createandreturn a new object. See help(type) for accurate signature.
||----------------------------------------------------------------------| Data and other attributes defined here:
|| __hash__ =None
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
2020-11-25 Python 继承
2019-11-25 Python 项目:外星人入侵--第三部分