member variable string gets treated as Tuple in Python

前端 未结 3 1410
星月不相逢
星月不相逢 2020-12-08 17:58

I am currently learning Python with the help of CodeAcademy. My problem may be related to their web application, but my suspicion is I am just wrong on a very fundamental le

3条回答
  •  盖世英雄少女心
    2020-12-08 19:01

    In your __init__, you have:

        self.model = model,
        self.color = color,
    

    which is how you define a tuple. Change the lines to

        self.model = model
        self.color = color
    

    without the comma:

    >>> a = 2,
    >>> a
    (2,)
    

    vs

    >>> a = 2
    >>> a
    2
    

提交回复
热议问题