Last answered:

05 Jul 2023

Posted on:

25 Jun 2023

0

ask question self

please i have not understand the 'self' why we use it !!!

1 answers ( 0 marked as helpful)
Instructor
Posted on:

05 Jul 2023

0

Hey Boudina,


Thank you for reaching out and apologies for the late reply.


In Python, "self" is a convention used in object-oriented programming. It's a reference to the instance of the class, and it's used to access variables and methods associated with that instance.


When you instantiate a class, Python passes the instance as the first argument to the constructor method (__init__) and any other instance methods you call. By convention, this first argument is named "self".


Although it is a strong convention, the term "self" is not a keyword and could technically be replaced with another variable name. However, it's best to stick to "self" as it is widely understood and expected by other Python developers.


Hope this helps!


Kind regards,

365 Hristina

Submit an answer