在教程中,我读过套可以因为Python 2.6这样的定义:Python:改进的设置符号?
a_set = {"Members", "of", "set"}
但是,让我们说,我想实现a_set = set("Letters")
与符号。 a_set = {"Letters"}
在打印时不会呈现相同的输出:
>>> set1 = set("Letters")
>>> set2 = {"Letters"}
>>> print(set1, set2)
{'L', 'r', 't', 'e', 's'} {'Letters'}
该教程是否错误?这里发生了什么?如果set2
不是一个集合,它是什么?
谢谢。是否可以通过使用'{}'-notation来实现'set1'? – Sahand
@Sandi不是。除非你想破解CPython源代码。有没有理由不能使用'set'? –
'{*'letters'}'适用于Python 3.6。虽然没有在2.x上试用它。 – ayhan