Dec-04-2019, 01:56 PM
From what I understand after doing some reading (I'm still new to this!):
class Foo makes spam a method which returns 100 when called, whilst class Bar uses the property getter method to get the value of attribute spam (which is 100). In other words, class Bar can be rewritten as:
Am I missing something out..? (sorry this is the best I could explain/putit in words)...
class Foo makes spam a method which returns 100 when called, whilst class Bar uses the property getter method to get the value of attribute spam (which is 100). In other words, class Bar can be rewritten as:
class Bar: def __init__(self,spam=100): self.spam = spam def get_spam(self): return self.spam >>>bar = Bar() >>>bar.spam 100line 12 in your snippet returns some funny stuff because the spam attribute of foo doesn't really exist, whereas line 14 works because the method spam() is defined in lines 3-4.
Am I missing something out..? (sorry this is the best I could explain/putit in words)...