Python知識分享網(wǎng) - 專業(yè)的Python學(xué)習(xí)網(wǎng)站 學(xué)Python,上Python222
Python 函數(shù)的多返回值
發(fā)布于:2023-09-12 10:47:42

Python 7天快速入門完整視頻教程https://www.bilibili.com/video/BV1o84y1Z7J1

 

Python    函數(shù)的多返回值

 

 

復(fù)雜業(yè)務(wù)情況,函數(shù)可以有多個返回值,類型也不限制。

語法是 return 返回值1,返回值2,...返回值n

 

def test():
    return 1, "python222", True

 

調(diào)用函數(shù)返回類型是元組tuple類型,當(dāng)然我們也可以通過多個變量接收也行;

 

def test():
    return 1, "python222", True


# 返回元組類型
result = test()
print(f"result={result},type={type(result)}")

# 通過多個變量接收
a, b, c = test()
print(a, b, c)

 

執(zhí)行返回值:

 

result=(1, 'python222', True),type=<class 'tuple'>
1 python222 True

 

 

轉(zhuǎn)載自: