Hey guys, I was wondering if you could clear up some things on classes for me. I have had a semi-easy time understanding python and programming concepts up to this point but now am having a real tough time on classes. I think it is because my book uses long and confusing examples to show how they work. Anyways, I made a short, 8 line class to try and understand what is going on.
class Player:
"""Enter name as string"""
def __init__(self, playername):
self.name = playername
def getName(self):
return self.name
My first question is, the self.name under the constructor, I do not really unerstand what to put under here (the constructor). For this example it is easy because I only have one method but what else would be put under there and how would they work with the methods? Second, when I create an object of this class ( I hope I am using the right vocab :P ) "josh", I can use josh.name to get the same result as josh.getName(). So what is the purpose of the getName() method?
If anyone wants to answer this that would be great, or another thing that could be great is if someone made a slightly more complex class and explained how everything worked together. Thanks in advance!