Posts

Showing posts from April, 2021

Abstract Class and Methods in Python😊

Image
ABSTRACT CLASS Abstract classes  in Python are empty or Partially implemented classes . An abstract class can be considered as a  blueprint for other classes . It allows you to create a set of methods that must be created within any child classes built from the abstract class.  A class which contains  one or more abstract methods   is called an  abstract class. An abstract method is a method that has a  declaration  but does not have an  implementation . While we are designing large functional units we use an abstract class. When we want to provide a common interface for different implementations of a component, we use an  abstract class.   Note :  Every abstract class in  python should be a child of ABC class , which is present in the abc module. #abstract class concept from  abc  import  * class   Student ( ABC ):    pass stud1 = Student() When an incomplete method( Abstr...

Role of Instance, Class, Static Methods in Python✌

Image
  Instance Methods Instance methods  are most widely used methods. It receives the instance of the class as the first argument, which by convention is called  self , and points to the instance of our class . However it can take any number of arguments. Using the  self  parameter, we can access the other attributes and methods on the same object and can change the object state. Also, using the  self.__class__  attribute, we can access the class attributes, and can change the class state as well.  Therefore, instance methods gives us control of changing the object as well as the class state. class  Student:    def   __init__ ( self , name ):      self .name = name    def   printinfo ( self ):      self .city =  ''Tamil Nadu"      print ( 'My name is {} and I am from {}' . format ( self .name, self .cit...

Role Of super() in Python🤔

Image
  SUPER() The super() builtin returns a proxy object (temporary object of the superclass) that allows us to access methods and other properties of the base class.   Example 1 : class Person:      def __init__(self,name,age):      self.name = name      self.age = age class Student(Person):      def __init__(self,name,age,grade):      super().__init__(name,age)      self.grade = grade    def printGrade(self):      print('Student name is {} age is{}Grade is{}.format(self.name,self.age,self.grade)) stud1 = Student('tom',24,'A') stud1.printGrade() >> Student name is tom age is 24 and Grade is A From the above program, we can see that we have used the instances of the parent class in the child class using the super keyword, like this we can also call methods that defined inside the parent class into child class. Example 2 : From above example we can con...

Access Modifiers in Python✌

Image
ACCESS MODIFIERS           In most of the object-oriented languages access modifiers are used to limit the access to the variables and functions of a  class Types of Modifiers Python uses ‘_’ symbol to determine the access control for a specific data member or a member function of a class. Access specifiers in Python have an important role to play in securing data from unauthorized access and in preventing it from being exploited.   In python the representation of Public, Protected and Private access specifiers are as follows: 1. Public: eg:  name 2. Protected:  eg:  _name 3. Private: eg:  __name These access modifiers define how the members of the class can be accessed. Of course, any member of a class is accessible inside any member function of that same class.  Access Modifier: Public The members declared as Public are accessible from outside the Class through an object of the class. Access Modif...