【发布时间】:2013-08-20 19:07:14
【问题描述】:
我正在做 python 编程,这是其中的类单元。并且代码没有打印正确的答案。
class Car(object):
condition = "new"
def __init__(self, model, color, mpg):
self.model = model
self.color = color
self.mpg = mpg
def display_car(self):
print "This is a "+ self.color + self.model+ " with "+str(self.mpg)+"MPG"
my_car = Car("DeLorean", "silver", 88)
print my_car.display_car()
我正在尝试打印 这是一辆 88 MPG 的银色 DeLorean。
【问题讨论】:
-
但是它打印了什么?
-
考希克,还要加空格:
'...self.color + " " +self.model...'
标签: python class concatenation