Greetings Sudanshu,

sudhanshu gautam wrote:
when we work on the oops in the python then we have to pass the first parameter as a self then the value of the other parameters .

Well, not explicitly. If you're familiar with OOPS in C++, self is analogous to the "this" pointer there. Also, you needn't call it self.

Writing something like

class A(object):
  def __init__(me, name):
     me.name = name
     print "The name is %s"%me.name

will work fine as well.

The actual identifier 'self' is just a convention.

for example:
class Student:
def __init__(self,name):
self.name <http://self.name>=name
print 'The name is',self.name <http://self.name>

a=student('sudhanshu')
a is an object of the student class
so __init__ is a constructor in which we do not need to call the function separately .

__init__ is not *a* constructor as much as it is *the* constructor method. It is one of the many class methods that have special meanings. If you want the entire list, try http://docs.python.org/reference/datamodel.html#special-method-names


Now If I placed the name of the constructor rather than the __init__
__baba___ so will it also work as a constructor or constructor has specified already if yes then give me list of them

__baba__ is not a special function so it will have no special significance. It is treated as any other class method.

I believe the URL above has what you're looking for.

Thanks

--
~noufal
http://nibrahim.net.in/
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to