Skip to content

OOPs in Python

surendrabisht edited this page Aug 23, 2020 · 2 revisions

Object oriented Approach

We can also use object oriented approach in python to solve any problem. So we can have classes in python.

In Python, we can add any property to object even though not defined in class.


class Python:
      pass

Now using object of class

language=Python()
language.AddAnyNewProperty="Addded Static Type checking in Python"

print(language.AddAnyNewProperty)

Basic Concepts

  1. self -> denotes current object.
  2. __init__ -> to provide your own constructor
  3. __ is dunder which can be used to denote the function as special methods and can also be use for fields to make them use as private. Even though we cannot actually make the class variables private. Dunder used in variables make them visible outside little different from other variables. we have to specify it as object._classname__privateVariable
Clone this wiki locally