0

I tried to find an answer to this pretty specific question but nearly seems like nobody is asking that question and its not even hindering my progress but I just want to know why.

class Member:
    def __init__(self, name):
        self.name = name

    def getname(self):
        return self.name

member1 = Member("John")

print(member1.name)
print(member1.getname())

In this example I get the exact same result, I even checked with the type() function to see if there would be any difference but no.

Is there even any difference apart from one beeing a function. Is one of these methods superior to the other and if there is no difference why do so many people use a function to return a value?

And if this question has been asked already could you provide a link?

Thank you I really appreciate any effort

Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
Garak
  • 1
  • 1
    Well why do you expect the result to be different? – Willem Van Onsem Jun 30 '17 at 19:43
  • 2
    Possible duplicate of [Why use getters and setters?](https://stackoverflow.com/questions/1568091/why-use-getters-and-setters) – melpomene Jun 30 '17 at 19:48
  • 1
    Possible duplicate of [What is the benefit to using a 'get function' for a python class?](https://stackoverflow.com/questions/13852279/what-is-the-benefit-to-using-a-get-function-for-a-python-class) – Alter Jun 30 '17 at 19:51
  • @Alter Yeah, that looks like a better duplicate. – melpomene Jun 30 '17 at 19:52

0 Answers0