1. 程式人生 > >Can't convert 'int' object to str implicitly提示解決方法

Can't convert 'int' object to str implicitly提示解決方法

eg:

class Car:
    def __init__(self, newWheelNum, newColor):
        self.wheelNum = newWheelNum
        self.color = newColor
    def __str__(self):
        msg = "嘿。。。我的顏色是" + self.color + "我有" + self.wheelNum + "個輪胎..."
        return msg
    def move(self):
        print('車在跑,目標:夏威夷')
hellocar = Car(4, "白色")
print(hellocar)

   

修改: