问题:玩弄在函数之间交换变量的想法。
我正在执行以下代码:
def benefits():
list = ["Beautiful", "Explicit", "Simple", "Readability","Easy to share"]
return list
def statement(benefit):
print("The benifit is " + benefit )
def benefits_of_functions():
benefits_list = benefits()
for benefit in benefits_list:
print(statement(benefit))
benefits_of_functions()
我得到了错误:
The benifit is Beautiful
None
The benifit is Explicit
None
The benifit is Simple
None
The benifit is Readability
None
The benifit is Easy to share
None
我无法理解“无”。您能帮我弄清楚为什么在输出中吗?
答案 0 :(得分:2)
在statement
函数中返回而不是打印:
def benefits():
list = ["Beautiful", "Explicit", "Simple", "Readability","Easy to share"]
return list
def statement(benefit):
return "The benifit is " + benefit
def benefits_of_functions():
benefits_list = benefits()
for benefit in benefits_list:
print(statement(benefit))
benefits_of_functions()