热线电话:13121318867

登录
2018-12-19 阅读量: 734
如何在Python中返回多个值?

在Python中,我们可以从函数返回多个值。例如可以使用object函数

Object:这类似于C / C ++和Java,我们可以创建一个类(在C,struct中)来保存多个值并返回该类的对象。

# A Python program to to return multiple

# values from a method using class

class Test:

def __init__(self):

self.str = "geeksforgeeks"

self.x = 20

# This function returns an object of Test

def fun():

return Test()

# Driver code to test above method

t = fun()

print(t.str)

print(t.x)

0.0000
3
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子