What isPickle or Serialization and UnPickle or DeSerialization in python how to define.The process of converting an object from python

Image
Object Serialization The process of converting an object from python supported form to either file supported   form or network supported form, is called serialization (Marshalling or pickling) The  process of converting an object from either file supported form or network supported   form to a python-supported form is called deserialization (Unmarshalling or  unpickling).  Object Serialization by using Pickle  Object Serialization by using JSON  Object Serialization by using YAML  Object Serialization by using Pickle: We can perform serialization and deserialization of an object wrt file by using the pickle   module. It is Python's inbuilt module.  pickle module contains dump() function to perform Serialization(pickling).  pickle.dump(object,file)  pickle module contains load() function to perform Deserialization (unpickling).  object = pickle.load(file)  Program to perform pickling and unpickling of Em...

What is super methon in python How to Call Method of a Particular Super Class...

super() Method:

super() is a built-in method that is useful to call the superclass constructors, variables, and methods from the child class.

Demo Program-1 for super():

class Person:

    def __init__(self,name,age):

        self.name=name

        self.age=age 

    def display(self):

       print('Name:',self.name)

       print('Age:',self.age) 


class Student(Person):

    def __init__(self,name,age,rollno,marks):

        super().__init__(name,age)

        self.rollno=rollno

        self.marks=marks

    def display(self):

        super().display()

        print('Roll No:',self.rollno)

        print('Marks:',self.marks) 

s1=Student('Durga',22,101,90) 

s1.display() 

Output:

Name: Durga

Age: 22

Roll No: 101

Marks: 90

In the above program, we are using the super() method to call the parent class constructor and 

display() method



#Demo Program-2 for super():

class P:

    a=10

    def __init__(self):

        self.b=10

    def m1(self):

        print('Parent instance method')

    @classmethod

    def m2(cls):

        print('Parent class method')

    @staticmethod

    def m3():

        print('Parent static method') 

class C(P):

    a=888

    def __init__(self):

        self.b=999

        super().__init__()

        print(super().a)

        super().m1()

        super().m2()

        super().m3()

c=C()


Output:

10

Parent instance method

Parent class method

Parent static method

In the above example, we are using super() to call various members of the Parent class.

Comments

Popular posts from this blog

Rajasthan Royals Vs Kings 11punjab dreem 11 prediction playing 11 pitch report

What isPickle or Serialization and UnPickle or DeSerialization in python how to define.The process of converting an object from python

How to Call Method of a Particular Super Class in python types of super method examples