Understanding the self Parameter in Classes in Python


Use the self parameter in class methods to access instance variables and methods.

Source Code

class MyClass:
    def __init__(self, name):
        self.name = name
    def say_hello(self):
        print(f"Hello {self.name}")
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments