Skip to content

Python OOPS !!

Nikhil George edited this page Apr 27, 2016 · 3 revisions

Class Attributes | Class Methods | Instance Attributes | Instance Methods

class className:
    classAttr=1
    def classFun(classObj):
        print(classObj.classAttr)
    def instanceFun(self):
        self.instanceAttr=10
        print(self.instanceAttr)
obj = className()
obj.instanceFun()
className.classFun(obj)

And see the stuff below…​they say it’s advanced usage but WFT !! Ref

class Foo(object):
    bar = 1
    def bah(obj):
        print obj.bar
obj = Foo()
obj.bah()
Foo.bah(obj)

O/P
1
1
class Foo(object):
    bar = 1
    def bah(self):
        print self.bar
obj = Foo()
obj.bah()

O/P
1

Clone this wiki locally