任何人都可以告诉这段代码有什么问题(python :()

时间:2013-09-25 11:01:45

标签: python

只想打印红色和蓝色 -

class color:
    def __init__(self,r,b):
        self.r = r
        self.b = b

        def displaycolor(self):
            print "The first should be :" self.r
            print "The 2nd should be :" self.b
pagal=color("Red","blue")
pagal.displaycolor()

1 个答案:

答案 0 :(得分:3)

两个问题:打印时缩进和字符串连接:

class color:
    def __init__(self,r,b):
        self.r = r
        self.b = b

    def displaycolor(self):
        print "The first should be :", self.r
        print "The 2nd should be :", self.b
pagal=color("Red","blue")
pagal.displaycolor()