How is “self” explicitly defined in a method?



How is “self” explicitly defined in a method?..

Answer / chaitanya

“Self” is a reference variable and an instance attribute that is used instead of the local variable inside the class. The function or the variable of the self like self.x or self.meth() can be used in case the class is not known. There are no variables declared as local. It doesn’t have any syntax and it allow the reference to be passed explicity or call the method for the class that is in use. The use of writebaseclass.methodname(self, <argument list>) shows that the method of _init_() can be extended to the base class methods. This also solves the problem that is syntactic by using the assignment and the local variables. This tells a way to the interpreter the values that are to be used for the instance variables and local variables. The use of explicit self.var solves the problem mentioned above.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

What is pytest?

0 Answers  


I am from non technical Background. In how many days I can learn the python? and What I need to do for that?

0 Answers  


How do I get a list of all files (and directories) in a given directory in Python?

0 Answers  


Name the file-related modules in python?

0 Answers  


Which python memory profiler is recommended?

0 Answers  






Which of the following statements create a dictionary? (Multiple correct answers possible)

0 Answers  


Where is the math.py (socket.py, regex.py, etc.) Source file?

0 Answers  


Do you know in python what are iterators?

0 Answers  


What is monkey patching?

0 Answers  


Explain how to delete a file in Python?

0 Answers  


Can I make a website with python?

0 Answers  


How do you add elements to a list in python?

0 Answers  


Categories