Posts

Showing posts from October, 2021

Python self Variable

Python self Variable Python self variable is used to bind the instance of the class to the instance method. We have to explicitly declare it as the first method argument to access the instance variables and methods. This variable is used only with the instance methods. In most of the Object-Oriented programming languages, you can access the current object in a method without the need for explicitly having it as a method parameter. For example, we can use “this” keyword to access the current object in Java program. But, in Python we have to explicitly declare the object instance as “self” variable Example1: class Emp : def __init__ ( self , name , empid ): self .name = name self .empid = empid print ( id ( self )) def e1 ( self ): print ( "Name of Emp: " , self .name) print ( "Emp id is : " , self .empid) e = Emp( 'VDS' , 100 ) print ( id (e)) e.e1() POINTS TO REMEMBER: Python self variable is not a reserved key...