我正在研究理解.我得到了print(x)部分(我认为.它打印了传递'in'测试的x的值)但是为什么它之后也会返回None列表呢?
>>> g
['a', 'x', 'p']
>>> [print(x) for x in g]
a
x
p
[None, None, None] #whats this?
Run Code Online (Sandbox Code Playgroud) 我试图理解为什么外部print返回None。
>>> a = print(print("Python"))
Python
None
>>> print(type(a))
<class 'NoneType'>
Run Code Online (Sandbox Code Playgroud)
我注意到:
>>> a = print("hey")
hey
>>> type(a)
<class 'NoneType'>
Run Code Online (Sandbox Code Playgroud)
谁能解释一下这里发生的一般情况?谢谢!
我从API获取数据并使用转换JSON requests,然后从dict中的列表中的每个dict中提取一个值:
response = requests.get("http://api.open-notify.org/astros.json")
astros = response.json()
print(astros["number"])
[print(astronaut['name']) for astronaut in astros['people']]
Run Code Online (Sandbox Code Playgroud)
输出根据需要给出了名称列表,但是后面跟着6个无值的列表; 我不明白为什么.