[Python] Issue with my Classes in Python (I have made projects with classes before, so this...

Discussão em 'Python' iniciado por Stack, Fevereiro 16, 2025.

  1. Stack

    Stack Membro Participativo

    For some reason, my Python code doesn't work and I am trying to understand why that is exactly.

    The error reads:

    ERROR!
    Traceback (most recent call last):
    File "<main.py>", line 10, in <module>
    File "<main.py>", line 3, in __init__
    AttributeError: 'Car' object has no attribute 'model'


    My code looks like this:

    class Car:
    def __init__(self, model, year, color, forSale):
    self.model == model
    self.year == year
    self.color == color
    self.forSale == forSale



    car1 = Car("Mustang", 2024, "red", False)
    print(car1)


    I programmed this on Programiz, which has an online Python compiler. The link is here: https://www.programiz.com/python-programming/online-compiler/

    Thank you for reading this, and have a good day.

    Continue reading...

Compartilhe esta Página