我收到一個錯誤....我知道我做錯了什麼,但不知道如何解決它。我知道我不能將一個字符串添加到一個整數...任何想法,我會很感激!python總結
self.variables['gas'] = 'gas'+add
TypeError: Can't convert 'int' object to str implicitly
我的代碼:
class Cars:
def __init__(self, **kwargs):
self.variables = kwargs
def set_Variable(self, k, v):
self.variables[k] = v
def get_Variable(self, k):
return self.variables.get(k, None)
def add_gas(self, add, gas):
self.variables['gas'] = gas+add
def main():
mercedes = Cars(gas = 3)
print (mercedes.get_Variable('gas'))
print(mercedes.add_gas(4))
if __name__ == "__main__": main()
您的回溯和您的示例代碼不匹配。 – 2013-02-27 17:39:27