Use of 'self' in classes of python

Submitted 3 years, 2 months ago
Ticket #345
Views 237
Language/Framework Python
Priority Low
Status Closed

I want to know the purpose self in python which are used in classes?

What happens if we do not use self ,does it raise any errors during compilation?

Submitted on Feb 10, 21
add a comment

1 Answer

Verified

self represents the instance of the class. By using the “self” keyword we can access the attributes and methods of the class in python. It binds the attributes with the given arguments.

The reason you need to use self. is because Python does not use the @ syntax to refer to instance attributes. Python decided to do methods in a way that makes the instance to which the method belongs be passed automatically, but not received automatically: the first parameter of methods is the instance the method is called on

Submitted 3 years, 2 months ago


Latest Blogs