class Dog : # Class Object Attribute species = 'mammal' def __init__ ( self , breed , name ): self . breed = breed self . name = name Lets break down what we have above.The special method __init__() is called automatically right after the object has been created, similer to construct() in php self argument is necessary in python, php has default so no need to pass in php sam = Dog ( 'Lab' , 'Sam' ) //here creating the instance of the class, no need to pass new keyword in python Inheritance: class Animal : def __init__ ( self ): print ( "Animal created" ) def whoAmI ( self ): print ( "Animal" ) class Dog ( Animal ): // Inherating the Animal Class def __init__ ( self ): Animal . __init__ ( self ) print ( "Dog created" ) Error Handling & Exception : try : f = open ( 'testfile' , 'r...
Trying to Learn new things on drupal.