+ 1
Python
Can someone please explain this to me https://code.sololearn.com/ca6a12a5A114/?ref=app
3 Respuestas
0
Hi, Abdullah . What to explain?
0
What the class expression is doing
0
class expression(object):
def symbols(self):
if not hasattr(self, '_symbols'):
self._symbols = self._getsymbols()
return self._symbols
def _getsymbols(self):
"""
return type: list of strings
"""
raise NotImplementedError
Abdullah Will try to explain what I understand about it:
1. Defining the class named "expression".
2. Inheriting from the super class "object".
3. defining the method named symbols(self) and telling to interpretator this method is belongs to the "expression" class.
4. hassattr(self, '_symbols') is the built-in method in Python, parameters are hasattr(object, name) where,
object — object name of the class
name — attribute name to be checked.
Checking in expression class if it has '_symbols' class attribute. If not has , then it will be in True.
5. Assigning the result of _getsymbols(self) method to the _symbols attribute value , we know symbols method returns True, then we can see NotImplementedError.