Monday, June 29, 2015

June1

##//python

class A(object):
    def __init__(self):
        self.x = 'Hello'
        self.y = 'You know nothing'

    def method_a(self, foo):
        print self.x + ' ' + foo

    def showmoretest(self, boo):
        print self.y + ' ' + boo

a = A()               # We do not pass any argument to the __init__ method
a.method_a('Universe!')
a.showmoretest('john snow')

print "-----------------------------------"

class MyClass(object):
     i = 123
     def __init__(self):
         self.i = 345

a = MyClass()
print a.i
345
print MyClass.i
123

print '------------------------------'

class foo:
    def bar(self):
            print "hi"
f = foo()
f.bar()
foo.bar(f)

print '-------------------------------------'

class Person:

    '''Doc - Inside Class '''

    def __init__(self, name):
        '''Doc - __init__ Constructor'''
        self.n_name = name        

    def show(self, n1, n2):
        '''Doc - Inside Show'''
        print self.n_name
        print 'Sum = ', (n1 + n2)

    def __del__(self):
        print 'Destructor Deleting object - ', self.n_name

p=Person('Jay')
p.show(2, 3)
print p.__doc__
print p.__init__.__doc__
print p.show.__doc__


No comments:

Post a Comment