Classes: just like collections?


I've just started the Classes "Instantiating Your First Object" lesson....

May be stupid questions (easy to guess that further classes will make more useful stuff) but for what is showed so far...

1) arent' they behaving like normal collections with just more complex coding (call item in a list)?
2) why first parameter is needed to let python to know how to refers to the object? since it's in "inside" object thing shouldn't it be hidden (i mean auto-made by python without being written by the programmer, just like it does by assignigning to a variable it's type (string, int)? let me try to explain a little better...
in the exercize i did this:

class Animal(object):
    def __init__(self, xxx): = xxx
zebra = Animal("Jeffrey")


why it can't be simply:

class Animal(object):
    def __init__(xxx): = xxx (or even just ".name = xxx" since it's inside class thing)

what seems to me is that u need to pass through a lot more parameters/variables/etc than "logically" needed...

Am i missing smth?


well, yes and no. List are classes, think about it, look at this:


we clearly use calling a method syntax here.

Javascript does this (and other languages), its done automatic. There is a discussion if python should adopt this as well, so far the people in charge of python don't want this. using self gives more control and is more explicit, self seems to stay for now


1) yes i've noticed the similitude, just thought it was the opposite XD

2) any particular reason you may know for this? what control does explicit declaration gives?


no, but van rossum (creator of python) explains it in the blog (link to blog)


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.