【发布时间】:2021-03-19 15:59:18
【问题描述】:
我有以下问题。
class Operacoes(object):
def __init__(self, *args):
self.__numero = args
def get_numero(self) -> int:
return self.__numero
x = Operacoes(10).get_numero()
print(x)
#(10,)
这让我很感兴趣,为什么有人知道怎么告诉我?
args,在第 10 次情况下应该返回一个 int,但返回的是一个元组。
【问题讨论】:
-
10 作为元组传递,就像您使用
*args -
我看不出在这里使用
*args的意义。只需执行def __init__(self, num):即可获得所需的输出。
标签: python python-3.x