Interfaces
Interfaces
Interfaces Describe how you can interact with an object without necessarily implementing it. >>>s ='Hi there!' >>>1+2 >之>print(s) TypeError:unsupported operand <string object-at...> type(s)for +'int'and int' Hi there! 3
Interfaces Describe how you can interact with an object without necessarily implementing it. >>> s = 'Hi there!' >>> print(s) <string object at ...> Hi there! >>> 1 + 2 TypeError: unsupported operand type(s) for +: 'int' and 'int' 3
Magic Methods
Magic Methods
Magic Methods These are specially named methods that are callable outside the ordinary dot notation. Example:__init__ class A: def__init__(self,num):- specifies >>a=A(5) self.numnum Equivalent to: a =A.__new__(A)) a.-init-(5)】
Magic Methods These are specially named methods that are callable outside the ordinary dot notation. Example: __init__ class A: def __init__(self, num): self.num = num >>> a = A(5) specifies Equivalent to: a = A.__new__(A)) a.__init__(5)