r/learnpython • u/Forward-Ride2950 • 19d ago
Trying to understand Class, Object, Instance, and self in Python. Is my understanding correct?
I'm currently learning OOP in Python and wrote down some questions regarding object and instance for following code
=
= ```
1) is ?
:- is
2) is ?
:- is and is
3) ?
:- is in is and
pass
50
Upvotes
View all comments
1
u/backfire10z 19d ago edited 19d ago
Yeah, looks about right.
The `self` parameter is automatically passed in by Python when you call a method of the instance.
For example, suppose your Car class also had `def print_color(self): print(self.color)`. You would call `car1.print_color()`, and then `self` would be `car1`.
You can actually also do `Car.print_color(car1)`, but that’s not idiomatic and there are some edge cases where this may cause unexpected behavior.