gpt4 book ai didi

python : How and why is this syntax working ? {1,2,3,4}

转载 作者:太空狗 更新时间:2023-10-30 01:55:17 24 4
gpt4 key购买 nike

据我们所知,

{} # Represents a dict

{'one': 1} # Again a dict

这是一组的方式和原因:

{'one', 'two', 'three', 'four'} # I thought it should give syntax error

但它给出了:

set(['one', 'two', 'three', 'four']) # Strange ?? [ Should this happen ? ]

您能否提供一些讨论相同内容的官方文档的链接?

最佳答案

Set literals是已向后移植到 2.7 的 3.x 功能。

这是一个有用的功能 - 请注意,集合推导式也是允许的。

关于 python : How and why is this syntax working ? {1,2,3,4},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12779053/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com