我有以下返回数据的函数:
def get_comments():
for i in data:
comment_data = i['comments']
for z in comment_data:
comments = comment_data['data']
for j in comments:
comment = j['message']
print(comment)
Run Code Online (Sandbox Code Playgroud)
我想将此函数的输出保存到变量中。我使用的是打印而不是返回(在函数 get_comments 中),因为返回只返回数据的最后一行。这就是我试图解释的:
def hypothetical(x):
return x
z = hypothetical(get_comments())
print(z)
Run Code Online (Sandbox Code Playgroud)
然而,变量 z 的输出是“无”。
当我尝试其他一些值(即)时:
z = hypothetical(5)
print(z)
Run Code Online (Sandbox Code Playgroud)
z当然等于5。
谢谢