What's the difference? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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"

22nd Dec 2018, 8:30 PM
Razf
Razf - avatar
4 Answers
+ 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).
22nd Dec 2018, 8:51 PM
Ulisses Cruz
Ulisses Cruz - avatar
+ 3
The first are instance attributes. The second are class attributes. https://www.python-course.eu/python3_class_and_instance_attributes.php
22nd Dec 2018, 8:34 PM
Ulisses Cruz
Ulisses Cruz - avatar
0
Mmmm if i create an objet with any of those ways the objet will be the same right? So....
22nd Dec 2018, 8:41 PM
Razf
Razf - avatar
0
i see... thanks!
22nd Dec 2018, 8:57 PM
Razf
Razf - avatar