+ 1
3rd May 2021, 2:21 AM
Abdullah
3 Respostas
0
Hi, Abdullah . What to explain?
3rd May 2021, 9:53 AM
Maksat Ramazanov
Maksat Ramazanov - avatar
0
What the class expression is doing
3rd May 2021, 1:58 PM
Abdullah
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.
3rd May 2021, 5:59 PM
Maksat Ramazanov
Maksat Ramazanov - avatar