【发布时间】:2017-11-20 06:51:28
【问题描述】:
我有一个代码。
scores = [19.0,19.0,20.0,20.0,21.0,21.0]
new_scores = set(scores)
print new_scores
输出: 设置([19.0, 20.0, 21.0])
我的问题: 为什么在输出前加上“set”这个词。 不设置应该直接返回列表“分数”中的唯一值。另外,如果我使用'list(set(scores))',那么我只得到不带前缀词'set'的唯一值列表的预期输出
【问题讨论】:
-
Why is the word 'set' prefixed to the output.为什么不呢?您应该向编写__str__方法的人询问set。 -
set是一个集合,而不是一个列表。