首页 > 解决方案 > 获取“无”而不是python中的值列表

问题描述

我目前在阿里云上做POC,没有授权分享信息。我是python的初学者。让我考虑一个例子来解决我的问题。

我得到none的不是值列表,

示例代码:

NumSet={1,2,3,4,5,6,7,8,9,10}
NumList = list(NumSet).reverse()
print(NumList)

输出:

None

我错过了什么?

标签: pythonpython-3.x

解决方案


list.reverse()就地反转列表并不返回任何内容(或返回None)。

NumList = list(NumSet)  # convert to list first
NumList.reverse()  # reverse in-place

这是正确的做法。


推荐阅读