如何通过访问类对象获取值?

问题描述 投票:0回答:0

如果您使用“=”或将对象作为参数发送给函数,则该对象必须给出整数类型的值。

class A:

    def __init__(self, value: int) -> None:
        self.__value = value

    def inc(self) -> None:
        self.__value += 1

a = A(8)
a.inc()
a.inc()

g = a

print(g) # 10
print(type(g)) # int
python class object arguments equals
© www.soinside.com 2019 - 2024. All rights reserved.