Object Oriented Programing in Python

THIS PAGE IS UNDER DEVELOPMENT

Object

Class

class MyClass:
    
    attr = "I am a class attribute!"

    def f(self):
        return 'hello world'

Class variable

Method

Instance

x = MyClass()

Instantiation

Inheritance

Polymorphism

Overloading

How to create a class

TODO: example

Class constructor

The first method init() is a special method, which is called class constructor or initialization method that Python calls when you create a new instance of this class.

Class attributes

Static methods

Class methods

pass statement TODO move to basics

The pass statement is a null statement commonly used as a placeholder for functionality to be added later as in the foolowing example:

class MyClass(object):
    def method1(self):
        pass

    def method2(self):
        print "I am method2"

If you left method1 empty, it would return an indentation error:

class MyClass(object):
    def method1(self):
       
    def method2(self):
        print "I am method2"
  File "<string>", line 4
    def method2(self):
      ^
IndentationError: expected an indented block

We can do the same thing in an empty function or class as well.

def function(args):
    pass

class example:
    pass