一:问题
python中函数可以一次返回多个值么?
二:回答
可以的,其一次返回的多个值会被打包成元组
如下所示:
def demo2(name, age): content = f"name is {name}, age is {age}" return name,age,content if __name__ == "__main__": data = demo2("mmkx", 20) print(type(data)) print(data) >>> 程序运行结果如下: >>> <class 'tuple'> >>> ('mmkx', 20, 'name is mmkx, age is 20')
上面函数demo2一次性返回了3个值,即name、age、content,这3个值返回的类型为tuple即元组,数据变成(name,age,content)
标签:__,返回,name,python,age,值会,元组,content From: https://www.cnblogs.com/miaomiaokaixin/p/17861698.html