0
What's the difference?
class Car: def __init__(self): self.wheels = 4 self.max_speed = 250 self.color = "red" class Car: wheels = 4 max_speed = 250 color = "red"
4 Respostas
+ 2
If you create only ONE object.
But if you create more objects, in the first situation, every object will have it's own wheels, max_speed and color.
But in the second situation with many objects, you will see that all of them share the wheels, max_speed and color,
because those attributes are in the CLASS (but you can access them from the objects).
+ 3
The first are instance attributes.
The second are class attributes.
https://www.python-course.eu/python3_class_and_instance_attributes.php
0
Mmmm if i create an objet with any of those ways the objet will be the same right? So....
0
i see... thanks!