Python 如何将列表从一个函数传递到另一个函数?

Python 如何将列表从一个函数传递到另一个函数?,python,python-3.x,list,function,Python,Python 3.x,List,Function,问题:玩弄在函数之间交换变量的想法 我正在执行以下代码: def benefits(): list = ["Beautiful", "Explicit", "Simple", "Readability","Easy to share"] return list def statement(benefit): print("The benifit is " + benefit ) def benefits_of_functions():

问题:玩弄在函数之间交换变量的想法

我正在执行以下代码:

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

我不能理解“没有”。您能帮我弄清楚为什么会出现在输出中吗?

语句中返回而不是打印
函数:

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()

因为您的
语句
函数只打印一些内容,不返回任何内容,所以它隐式返回
None
。在函数的
优点
函数中,循环列表,然后打印将列表中的项目传递到
语句的结果,该语句将打印消息,但您正在打印该结果,即
def语句
应该只
返回“好处是”+好处
,而不是
打印它。注意,重要的是要理解,不是将变量传递到函数中,而是传递对象。