代码之家  ›  专栏  ›  技术社区  ›  MrXQ

将函数返回作为参数传递给另一个函数

  •  0
  • MrXQ  · 技术社区  · 5 年前

    如何获取用户在函数中输入的列表 take_list() 并将其传递给函数 no_duplication() ?

    在线路上: no_duplication(k)

    def take_list():
        k = []
        i = 0
        list_length = int(input("how many elements your list has ? \n "))
        while i < list_length:
            element = int(input("enter you list elements : "))
            k.append(element)
            i += 1
        print(k, "  is your list")
        return k
    
    def no_duplication(k):
        k = set(k)
        k = list(k)
        print(k, " Your list without duplications")
     
    
    take_list()
    no_duplication(k)
    
    1 回复  |  直到 5 年前
        1
  •  1
  •   Tugay    5 年前

    您需要将返回值赋给一个新变量并将其传递给 no_duplication 作为参数:

    k = take_list()
    no_duplication(k)