Section 1/4self in Any Instance Method
self in Any Instance Method
Both lines do the same thing. d.bark() is just shorthand — Python fills in self with d automatically.
The self Keyword
You already used self in __init__. The next step is using it correctly in every other instance method too. Without self., you create a local variable instead of changing the object itself.
self in Any Instance Method
class Dog:
def bark(self):
print(f"{self} says Woof!")
d = Dog()
d.bark() # Python calls: Dog.bark(d)
Dog.bark(d) # identical — self IS the object dBoth lines do the same thing. d.bark() is just shorthand — Python fills in self with d automatically.