类似于类,但也应该在类内工作。我不确定是否可能,也不确定要搜索的关键字是否正确,因此如果已经有答案,我深表歉意。你知道吗
例如,我的意思是像这样-
def location():
x = 5
y = 0
z = 0
return x,y,z
然后输入location().x,得到数字5。在我看来,用location().x
而不是location()[0]
要好得多。你知道吗
编辑:我要求的是这种方式,而不是类,因为您可能希望将它放在类中,比如objectInfo( object ).getLocation().x
Tags:
您可以使用"bunch":
使用^{} :
使用
namedtuple
,仍然可以使用索引[..]
访问值:更新
如果使用Python 3.3+,还可以使用^{} :
否则,使用以下类(来自上面的
SimpleNamespace
链接):你可以把它当作矩阵
定义(x,y,z): x=1 y=7 z=10`` 返回A=[x,y,z]
在你可以用这种方法得到numpers之后,A[1]代表x。 我想你明白我的意思,这是一种把变量连成一个序列的方法
相关问题 更多 >
编程相关推荐