Object Oriented programming in Python What is coming

Object Oriented programming in Python

What is coming up Class structure Inheritance

Class structure class Class. Name: <statement-1>. . . <statement-N>

Class structure No constructor needed Variables can be initialized in the declaration All methods and variables are public __init__() method behaves like a constructor if declared

Class structure class My. Class: "A simple example class" i = 12345 def f(self): return 'hello world' Var = My. Class() Var. something = “new value”

Inheritance class Derived. Class. Name(Base. Class. Name): <statement-1>. . . <statement-N> class Derived. Class. Name(modname. Base. Class. Name):

Inheritance class Derived. Class. Name(Base 1, Base 2, Base 3): <statement-1>. . . <statement-N>

Inheritance

Inheritance class Cat(Animal): def talk(self): return 'Meow!' class Dog(Animal): def talk(self): return 'Woof!' animals = [Cat('Missy'), Cat('Mr. Mistoffelees'), Dog('Lassie')] for animal in animals: print animal. name + ': ' + animal. talk() # prints the following: # # Missy: Meow! # Mr. Mistoffelees: Meow! # Lassie: Woof!

Conclusion All data and methods are public Python supports multiple inheritance Dynamic binding for a static scope Memory management in Python involves a private heap containing all Python objects and data structures. “Python memory manager”
- Slides: 10