python中向函数传递列表

1、

python中向函数传递列表,提高处理列表的效率。

>>> def a(x):          ## 定义函数的形参x为可迭代对象
    for i in x:
        print(f"hello,{i.title()}")

        
>>> b = ["aaa","bbb","ccc","ddd"]   ## 实参定义为列表,实现向函数中传递列表
>>> a(b)
hello,Aaa
hello,Bbb
hello,Ccc
hello,Ddd
>>> for i in b:                     ## 简洁实现方式
    print("hello",i.title())

    
hello Aaa
hello Bbb
hello Ccc
hello Ddd
原文地址:https://www.cnblogs.com/liujiaxin2018/p/14511938.html