Constructor and Destructor

Python In Hindi – Python Constructor and Destructor In Hindi

Python

Python In Hindi – Python Constructor And Destructor In Hindi – Python Constructor Ek special type Ka member function Hota Hai, Jo Aapne class Ke Name Jaisa Hota Hai And Python Destructor Ye Bhi Ek special type member function Hota Hai, Jo object Ko destroy Kar Deta Hai |

Previous Post Also Read :- PHP Classes/Objects

Python Constructor and Destructor In Hindi

Is Post Me Ham Constructor And Destructor In Hindi Ke Bare Me Janne Wale Hai Wo Bhi Step By Step In Hindi |

Constructor And Destructor In Python In Hindi Ka Istemal Keval OOPs Me Hi Hota Hai |

Python Constructor in Hindi

What is Python Constructor in Hindi – Python Constructor Ek special type Ka member function Hota Hai, Jo Aapne class Ke Name Jaisa Hota Hai Jis Class Ka Constructor Bana Ho, Agar Usi Class Ka Jab Object Jab Banta hai | Tab Vo Automatically Call Hota Hai |

Constructor ka koi bhi return type nhi hota hai | Void Bhi Return Nhi Karta Hai, Agar Koi Value Ko Initialize Karna Ho to Alag se Uska Member Function Bana Kar Use Object Se Sath Access Karta Padta Hai | Constructor Ye Kam Sirf Object banate Waqt hi kar deta hai |

Constructor ko Ham Class Ke Under And Bahar Bhi Define Kar Sakte Hai |

Python me Constructor Ko Create Karne Ke Liye __init__() Functions Ka Istemal Karna Hota Hai |

Example:

Python Class Ko Define Kar Diya Hai. Lekin Ab Ham Class Ke Under Function Create karte Hain __init__() for Construct Karne ke Liye.

Class Person():
  	def __init__(self):
      	print("This Is Constructor Call")
        
    def SetFullName(self, firstname , lastname):
      self.firstname = firstname
      self.lastname = lastname
      
    def PrintFullName(self):
      print(self.firstname, " " ,self.lastname")

Student1 = Person()     # automatically call constructor  
Student1.SetFullName("Danish","Ali")   #set value
Student1.PrintFullName()                    

Program Ko Understand Karne ke liye Niche Point Ko Read Kare |

  • Class Person(): – Hamne Yaha Par Person() Class Define ki Hai.
  • def __init__(self): – Hamne Yaha Par Constructor Define Kiya Hai Or Uske Under Ek Print Statement Write Ki Hai |
  • def SetFullName(): – Hamne Yaha Par Ek Functions Create Kiya Jisme First Name And Last Name Ko As an Input Lena Hai.
  • def PrintFullName(): – Hamne Yaha Par Jo First Name And Last Name Input Me Liye The Wo Print Kara Diye Hai.
  • Student1 = Person() – Yaha Par Person() Class Ka Ek Object Student1 Create Kiya Hai .
  • Student1.SetFullName(“Danish”,”Ali”) – Yaha Par Objects Student1 Ko Arguments Pass Kiye Hai.
  • Student1.PrintFullName() – Yaha Par Hamne Object Student1 Ko Print Kiya Hai.

Output:

This Is Constructor Call
Danish Ali

Student1 = Person() – Jaise Hi Hamne Program Me Student1 Object Create Kiya Tha To Constructor Automatically Call Ho Gaya Tha |

Python Destructor In Hindi

Destructor Ye Ek Special Type Ka Member Function Hota Hai, Jo Object Ko Destroy ya Delete Kar Deta Hai | Jab Object Program Se Bahar Ho Jata Hai, tab Destructor Automatically Call Hota Hai.

Constructor ko Ham Class Ke Under And Bahar Bhi Define Kar Sakte Hai |

Python me Constructor Ko Create Karne Ke Liye __init__() Functions Ka Istemal Karna Hota Hai |

Python me Destructor Ko Create Karne Ke Liye __del__() Functions Ka Istemal Karna Hota Hai |

Example:

Class Person():
  	def __init__(self):
      	print("This Is Constructor Call")
        
    def __del__(self):
      	print("This Is Destructor Call")
        
    def SetFullName(self, firstname , lastname):
      self.firstname = firstname
      self.lastname = lastname
      
    def PrintFullName(self):
      print(self.firstname, " " ,self.lastname")

Student1 = Person()     # automatically call constructor  
Student1.SetFullName("Danish","Ali")   #set value
Student1.PrintFullName()                    

Output:

This Is Constructor Call
Danish Ali

Yaha Par Waise Destructor Call Ho Gaya Hai. Lekin Output Me Print Nhi Hua Hai |

Output Me Check karne Ke Liye Niche Wala Example Dekhe.

Example2 :

Class Person():
  	def __init__(self):
      	print("This Is Constructor Call")
        
    def __del__(self):
      	print("This Is Destructor Call")
        
    def SetFullName(self, firstname , lastname):
      self.firstname = firstname
      self.lastname = lastname
      
    def PrintFullName(self):
      print(self.firstname, " " ,self.lastname")

Student1 = Person()     # automatically call constructor  
Student1.SetFullName("Danish","Ali")   #set value
Student1.PrintFullName()       
Student1.__del__()            

Output:

This Is Constructor Call
Danish Ali
This Is Destructor Call

Friends Mujhe Umeed Hai Ki Aapko Constructor And Destrutor in Python in Hindi Ke Bare Mai 100% Jankari Ho Gayi Hogi | Agar Aapko Learn Karne Main Dikkat Aa Rahi Hai To Aap Mere Se Contact Kar Sakte Hai |

Yadi Aapne  HTML Full Course  And CSS Full Course And Python Full Course And PHP Full Course Nhi Read Kiya Hai To Aap Vah Bhi Read Kar Sakte Hai |

Leave a Reply

Your email address will not be published. Required fields are marked *