member variable string gets treated as Tuple in Python

前端 未结 3 1300
星月不相逢
星月不相逢 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 18:38

    You've got a comma after those attributes in your constructor function.

    Remove them and you'll get it without a tuple

    0 讨论(0)
  • 2020-12-08 18:44

    yes, you have to remove comma from instance variables. from self.model = model, to self.model = model

    Nice to see, you are using Class variable concept, "condition" is class variable and "self.model", "self.color", "self.mpg" are instance variables.

    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题