我目前正在阿里云上做 POC,无权分享信息。我是python的初学者。让我考虑一个例子来解决我的问题。我得到none而不是值列表,示例代码:NumSet={1,2,3,4,5,6,7,8,9,10}NumList = list(NumSet).reverse()print(NumList)输出:None我缺少什么?
2 回答

潇湘沐
TA贡献1816条经验 获得超6个赞
list.reverse()
就地反转列表并且不返回任何内容(或返回None
)。
NumList = list(NumSet) # convert to list first NumList.reverse() # reverse in-place
这是正确的做法。

慕码人2483693
TA贡献1860条经验 获得超9个赞
list.reverse() 不会返回反转的列表。它所做的是就地反转列表。只要改成这个就行了
NumSet = {1,2,3,4,5,6,7,8,9,10}
NumList = list(NumSet)
NumList.reverse()
print(NumList)
添加回答
举报
0/150
提交
取消