我该怎么做呢?
class car:
def __init__(self, tires, color, age):
self.tires = tires
self.color = color
self.age = age
def gTires(self):
return self.tires
def gColor(self):
return self.color
def gAge(self):
return self.age
car1 = car(3, "Red", "1996")
carTires = car1.gTires
carColor = car1.gColor
carAge = car1.gAge
print("Your car 'car1' is done. It has " + carTires + " tires, is " + carColor + " and was made year " + carAge)
print()
print("But I heard you wanted it to have four tires?")
print("No problem (right?).")
car1 = car((car1.gTires + 1), (car1.gColor), (car1.gAge))
所以我的问题是关于如何使用属性,我是否必须像一开始那样设置所有变量?我的意思是,我不希望它们成为实例方法,但如果我不设置它们,它们似乎会是。另外,在最后一行我想更改 car1 拥有的轮胎数量的值,我不想更改所有其他属性。有没有办法在不设置所有其他属性的情况下做到这一点?
抱歉,如果这没有意义,请问您是否觉得难以理解我的问题。