{1:2,3:{4,5}}
为什么这样做?我以为我打错了字,但输出有效!
{4,5}是嵌套字典还是类似于列表的东西?
是的,您有一本包含一组的字典。字典是键-值配对的对象,其值可以是任何值,整数,列表,集合,数据框,字典等。
在这种特殊情况下,我们可以通过执行以下打印来看到这一点type
:
A = {1:2,3:{4,5}}
print(A, " is of type " , type(A))
print(A[1], "is of type " , type(A[1]))
print(A[3], "is of type " , type(A[3]))
正确输出:
{1: 2, 3: {4, 5}} is of type <class 'dict'>
2 is of type <class 'int'>
{4, 5} is of type <class 'set'>
如果将输出 A = {1:2,3:{4,4}}
{4} is of type <class 'set'>
由于set
包含独特元素,因此消除了重复。在这里您可以找到有关集合的更多信息
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句