社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

Elizabeth

Elizabeth 最近回复了
5 年前
回复了 Elizabeth 创建的主题 » python3中一个元组的集合

为了清楚起见,您需要验证元组 (1, 2) 是在 s 是吗?利用Python对可读性的灵活性可以帮助您理解为什么括号的数量是必要的。

set( # first paren is for calling the function set
    ( # second paren creates the object of items set should look at
        (1,2), # is an item in the set 
    )
    )

# output same as
set(((1,2), (1,2), (1,2)))

# output same as
t = ((1,2), (1,2), (1,2))
set(t)

# output same as
t = (1,2)
t = (t, t, t)
set(t)

# output same as
t = (1, 2)
set([t]*5)

set() 查找中的所有项 self 是的。如果您希望得到比设置变量更可读的解决方案。