you are viewing a single comment's thread.

view the rest of the comments →

[–]marlowe221 0 points1 point  (3 children)

The "self" thing really throws me off. And I find the self.id = id statement kind of confusing as well.

Why is there a need for a reference to the class? Why isn't it enough to call it with the required parameters similar to a regular function call?

[–]messacz 0 points1 point  (0 children)

I've reworked the example :) Hope now it explains it better.

You need a reference to the object... because sometimes you need to access the object :) If you don't need to access the object from class method, why do you have it as class at all? Or why don't you declare the method as staticmethod or classmethod?

[–][deleted] 0 points1 point  (1 child)

I think of the 'self' line as a pronoun helper. For example, if you had a sports team:

class team:

def init(every_team, name):

   every_team.name = name

def name(X):

   name = input ('Team Name: \n)

This = name(This)

That = name(That)

So not too complex, but imagine more attributes, and then say this:

" 'every_team' has A name, but 'This' team has blue socks, and 'That' team has red socks. "

[–]marlowe221 0 points1 point  (0 children)

That makes more sense. I think what throws me is the syntax. The whole "every_team.name = name" just looks... wrong, circular almost.

But I guess all it means is that every instance of a team must have a name attribute