同一类的Python类属性



Python类属性可以是同一类型吗?类似于:

class X:
def __init__(self, inputStr):
a = 0
b = X("Hello")

我不确定您需要它的用例是什么,也不确定它是否是一个理论问题。但是,如果您需要的话,您可以检查类继承。

class X:
def __init__(self, inputStr):
a = 0
self.inputStr = inputStr
class Y(X):
pass
obj = Y('Hello')
print(obj.inputStr)

最新更新