🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to Python Notes
Topic #105

Python self Parameter


The self Parameter

The self parameter is a reference to the current instance of the class.

It is used to access properties and methods that belong to the class.

Example

class Person:
  def __init__(self, name, age):
    self.name = name
    self.age = age

  def greet(self):
    print("Hello, my name is " + self.name)

p1 = Person("Emil", 25)
p1.greet()

Note: The self parameter must be the first parameter of any method in the class.


Why Use self?

Without self, Python would not know which object's properties you want to access:

Example

class Person:
  def __init__(self, name):
    self.name = name

  def printname(self):
    print(self.name)

p1 = Person("Tobias")
p2 = Person("Linus")

p1.printname()
p2.printname()

self Does Not Have to Be Named "self"

It does not have to be named self, you can call it whatever you like, but it has to be the first parameter of any method in the class:

Example

class Person:
  def __init__(myobject, name, age):
    myobject.name = name
    myobject.age = age

  def greet(abc):
    print("Hello, my name is " + abc.name)

p1 = Person("Emil", 36)
p1.greet()

Note: While you can use a different name, it is strongly recommended to use self as it is the convention in Python and makes your code more readable to others.


Accessing Properties with self

You can access any property of the class using self:

Example

class Car:
  def __init__(self, brand, model, year):
    self.brand = brand
    self.model = model
    self.year = year

  def display_info(self):
    print(f"{self.year} {self.brand} {self.model}")

car1 = Car("Toyota", "Corolla", 2020)
car1.display_info()

Calling Methods with self

You can also call other methods within the class using self:

Example

class Person:
  def __init__(self, name):
    self.name = name

  def greet(self):
    return "Hello, " + self.name

  def welcome(self):
    message = self.greet()
    print(message + "! Welcome to our website.")

p1 = Person("Tobias")
p1.welcome()

Want to go beyond the notes?

Join CodingNow 2.0's Python course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Python self Parameter – FAQs

Quick answers about learning Python self Parameter in Python.

This free note from CodingNow 2.0 explains Python self Parameter in Python — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Python topic on CodingNow 2.0, including Python self Parameter, is 100% free with no signup required.
With focused practice, most students grasp Python self Parameter in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now