http://learnpythonthehardway.org/book/ex6.html
Zed似乎在这里使用%r和%s互换,两者之间有什么区别吗?为什么不一直使用%s?
此外,我不知道在文档中搜索什么以查找更多信息.什么是%r和%s究竟叫什么名字?格式化字符串?
我正在做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()
Run Code Online (Sandbox Code Playgroud)
我正在尝试打印 这是一款带有88 MPG的银色DeLorean.