Python Tutorial

Python Self Parameter Explained With Example

What is Self Parameter in Python

The self argument is a reference to the current instance of the class, and it is used to access class-specific variables.

It doesn't have to be called self; you may call it whatever you like, but it must be the first parameter in any class function:

Code:

class Person1:

  def __init__():

    print(“python”)

  def my_func(self):

    print("hello”)

p = Person1()

p.my_func()
Output:
python
hello
Did you find this article helpful?