Python AttributeError:“tuple”对象没有属性“weight”
我不知道我做错了什么。我在这里写的每一件事都来自于这本书。ap1不是苹果的一个实例,它只是一个简单的元组。您需要显式调用Apple的Constructor:Python AttributeError:“tuple”对象没有属性“weight”,python,python-3.x,attributeerror,Python,Python 3.x,Attributeerror,我不知道我做错了什么。我在这里写的每一件事都来自于这本书。ap1不是苹果的一个实例,它只是一个简单的元组。您需要显式调用Apple的Constructor: class Apple: def __init__( self,w,c): self.weight=w self.color=c print("utworzono!") ap1=(280,"red") print(ap1) print(ap1.weight) 实际上,您使用的是
class Apple:
def __init__( self,w,c):
self.weight=w
self.color=c
print("utworzono!")
ap1=(280,"red")
print(ap1)
print(ap1.weight)
实际上,您使用的是api1=280,红色,而不是api1=Apple280,红色。你可以阅读更多关于。
ap1 = Apple(280, "red")