{"id":77921,"date":"2023-06-14T10:09:17","date_gmt":"2023-06-14T04:39:17","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/python-init\/"},"modified":"2024-10-14T23:54:36","modified_gmt":"2024-10-14T18:24:36","slug":"python-init","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/python-init\/","title":{"rendered":"Python __init__:\u00a0An Overview"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"what-is-__init__-in-python\"><strong>What is __init__ in Python?<\/strong><\/h2>\n\n\n\n<p>In Python, <code>__init__<\/code> is a special method known as the constructor. It is automatically called when a new instance (object) of a class is created. The <code>__init__<\/code> method allows you to initialize the attributes (variables) of an object.<\/p>\n\n\n\n<p>Here's an example to illustrate the usage of <code>__init__<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class MyClass:\n    def __init__(self, name, age):\n        self.name = name\n        self.age = age\n\n    def display_info(self):\n        print(f\"Name: {self.name}\")\n        print(f\"Age: {self.age}\")\n\n# Creating an instance of MyClass\nobj = MyClass(\"John\", 25)\n\n# Accessing attributes and calling methods\nobj.display_info()\n<\/code><\/pre>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Free Course<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/python-fundamentals-for-beginners\" class=\"courses-cta-title-link\">Python Fundamentals for Beginners Free Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Master Python basics, from variables to data structures and control flow. Solve real-time problems and build practical skills using Jupyter Notebook.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>13.5 hrs<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>4.55<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/python-fundamentals-for-beginners\" class=\"courses-cta-button\">\n                Enroll for Free\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-does-__init__-method-work\"><strong>How Does __init__() Method Work?<\/strong><\/h2>\n\n\n\n<p>The python __init__ method is declared within a class and is used to initialize the attributes of an object as soon as the object is formed. While giving the definition for an __init__(self) method, a default parameter, named <em>\u2018self\u2019<\/em> is always passed in its argument. This self represents the object of the class itself. Like in any other method of a class, in case of __init__ also \u2018self\u2019 is used as a dummy object variable for assigning values to the data members of an object.&nbsp;<\/p>\n\n\n\n<p>The __init__ method is often referred to as double underscores init or dunder init for it has two underscores on each side of its name. These double underscores on both the sides of init imply that the method is invoked and used internally in Python, without being required to be called explicitly by the object.&nbsp;This is a crucial aspect of <a href=\"https:\/\/www.nexsoftsys.com\/technologies\/python-development-services.html\" target=\"_blank\" rel=\"noreferrer noopener\">Python development services<\/a> , as it allows for the seamless creation and initialization of objects within various applications.<\/p>\n\n\n\n<p>This python __init__ method may or may not take arguments for object initialisation. You can also pass default arguments in its parameter. However, even though there is no such concept of Constructor Overloading in Python, one can still achieve polymorphism in the case of constructors in Python on the basis of its argument.<\/p>\n\n\n\n<p>Also Read: <a href=\"https:\/\/www.mygreatlearning.com\/blog\/set-in-python\/\" target=\"_blank\" rel=\"noreferrer noopener\">Set in Python \u2013 How to Create a Set in Python?<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"init-in-python-syntax-and-examples\"><strong>Init&nbsp;in Python: Syntax and Examples<\/strong><\/h2>\n\n\n\n<p>We can declare a __init__ method inside a class in Python using the following syntax:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nclass class_name():\n          \n          def __init__(self):\n                  # Required initialisation for data members\n\n          # Class methods\n                 \u2026\n                 \u2026\n\n<\/pre><\/div>\n\n\n<p>Let\u2019s take an example of a class named Teacher in Python and understand the working of __init__() method through it better.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Teacher:\n    # definition for init method or constructor\n    def __init__(self, name, subject):\n        self.name = name\n        self.subject = subject\n     # Random member function\n    def show(self):\n        print(self.name, \" teaches \", self.subject)\n T = Teacher('Preeti Srivastava', \"Computer Science\")   # init is invoked here\nT.show()\n<\/code><\/pre>\n\n\n\n<p>Now, for the scenarios where you are required to achieve polymorphism through __init__() method, you can go with the following syntax.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nclass class_name():\n          \n          def __init__(self, *args):\n                   Condition 1 for *args:\n                         # Required initialisation for data members\n                  Condition 2 for *args:\n                        # Required initialisation for data members\n                \n                    \u2026\u2026\u2026\n                    \u2026\u2026\u2026\n\n          # Class methods\n                 \u2026\n                 \u2026\n\n<\/pre><\/div>\n\n\n<p>In this case, the type of argument passed in place of <em>*args<\/em> decide what kind of initialisation has to be followed. Take a look at the example given below to get some more clarity on this.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Teacher:\n     def __init__(self, *args): \n\n         # Naming the teacher when a single string is passed\n         if len(args)==1 &amp; isinstance(args&#091;0], str):\n             self.name = args&#091;0]\n         \n         # Naming the teacher as well as the subject    \n         elif len(args)==2:\n             self.name = args&#091;0]\n             self.sub = args&#091;1]\n          \n         # Storing the strength of the class in case of a single int argument\n         elif isinstance(args&#091;0], int):\n             self.strength = args&#091;0]\n             \nt1 = Teacher(\"Preeti Srivastava\")\nprint('Name of the teacher is ', t1.name)\n \nt2 = Teacher(\"Preeti Srivastava\", \"Computer Science\")\nprint(t2.name, ' teaches ', t2.sub)\n \nt3 = Teacher(32)\nprint(\"Strength of the class is \", t3.strength)\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"types-of-__init__-constructor\"><strong>Types of __init__ Constructor<\/strong><\/h2>\n\n\n\n<p>There are mainly three types of Python __init__ constructors:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Default __init__ constructor<\/li>\n\n\n\n<li>Parameterised __init__ Constructor<\/li>\n\n\n\n<li>__init__ With Default Parameters<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1-the-default-__init__-constructor\"><strong>1. The Default __init__ Constructor<\/strong><\/h3>\n\n\n\n<p>The default __init__ constructor in Python is the constructor that does not accept any parameters, except for the \u2018<em>self<\/em>\u2019 parameter. The \u2018<em>self<\/em>\u2019 is a reference object for that class. The syntax for defining a default __init__ constructor is as follows:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nclass class_name():\n          \n          def __init__(self):\n                  # Constructor statements\n\n          # other class methods\n                 \u2026\n                 \u2026\n\n<\/pre><\/div>\n\n\n<p>The syntax for creating an object for a class with a default __init__ constructor is as follows:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nObject_name = class_name()\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"example\"><strong>Example:<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>class Default():\n    \n    #defining default constructor\n    def __init__(self):\n        self.var1 = 56\n        self.var2 = 27\n        \n    #class function for addition\n    def add(self):\n        print(\"Sum is \", self.var1 + self.var2)\n\nobj = Default()     # since default constructor doesn\u2019t take any argument\nobj.add()\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"2-parameterised-__init__-constructor\"><strong>2. Parameterised __init__ Constructor<\/strong><\/h3>\n\n\n\n<p>When we want to pass arguments in the constructor of a class, we make use of the parameterised __init__ method. It accepts one or more than one argument other than the <em>self<\/em>. The syntax followed while defining a parameterised __init__ constructor has been given below:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nclass class_name():\n          \n          def __init__(self, arg1, arg2, arg3, \u2026):\n                  self.data_member1 = arg1\n                  self.data_member2 = arg2\n                  self.data_member2 = arg2\n                  \u2026\u2026\n                  \u2026\u2026\n\n          # other class methods\n                 \u2026\n                 \u2026\n\n<\/pre><\/div>\n\n\n<p>We declare an instance for a class with a parameterised constructor using the following syntax:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nObject_name = class_name(arg1, arg2, arg3,\u2026)\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"example\"><strong>Example:<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>class Default():\n    \n    #defining parameterised constructor\n    def __init__(self, n1, n2):\n        self.var1 = n1\n        self.var2 = n2\n        \n    #class function for addition\n    def add(self):\n        print(\"Sum is \", self.var1 + self.var2)\n\nobj = Default(121, 136)              #Creating object for a class with parameterised init\nobj.add()\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"3-the-__init__-method-with-default-parameters\"><strong>3. The __init__ method with default parameters<\/strong><\/h3>\n\n\n\n<p>As you might already know, we can pass default arguments to a member function or a constructor, be it any popular programming language. In the very same way, Python also allows us to define a __init__ method with default parameters inside a class. We use the following syntax to pass a default argument in an __init__ method within a class.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nclass ClassName:\n         def __init__(self, *list of default arguments*):\n             # Required Initialisations\n    \n        # Other member functions\n                \u2026\u2026\n               \u2026\u2026.\n\n<\/pre><\/div>\n\n\n<p>Now, go through the following example to understand how the __init__ method with default parameters works.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Teacher:\n    # definition for init method or constructor with default argument\n    def __init__(self, name = \"Preeti Srivastava\"):\n        self.name = name\n     # Random member function\n    def show(self):\n        print(self.name, \" is the name of the teacher.\")\n        \nt1 = Teacher()                             #name is initialised with the default value of the argument\nt2 = Teacher('Chhavi Pathak')    #name is initialised with the passed value of the argument\nt1.show()\nt2.show()\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"use-of-python-__init__\"><strong>Use of Python __init__<\/strong><\/h2>\n\n\n\n<p>As discussed earlier in this blog and seen from the previous examples, __init__ method is used for initialising the attributes of an object for a class. We have also understood how constructor overloading can be achieved using this method. Now, let us see how this __init__ method behaves in case of inheritance.&nbsp;<\/p>\n\n\n\n<p>Inheritance allows the child class to inherit the __init__() method of the parent class along with the other data members and member functions of that class.&nbsp; The __init__ method of the parent or the base class is called within the __init__ method of the child or sub class. In case the parent class demands an argument, the parameter value must be passed in the __init__ method of the child class as well as at the time of object creation for the child class.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Person(object):\n    def __init__(self, name):\n        self.name = name\n        print(\"Initialising the name attribute\")\n\nclass Teacher(Person):\n    def __init__(self, name, age):\n        Person.__init__(self, name)   # Calling init of base class\n        self.age = age\n        print(\"Age attribute of base class is initialised\")\n        \n    def show(self):\n        print(\"Name of the teacher is \", self.name)\n        print(\"Age of the teacher is \", self.age)\n        \nt = Teacher(\"Allen Park\", 45)   # The init of subclass is called\nt.show()\n<\/code><\/pre>\n\n\n\n<p>From the above output, we can trace the order in which the __init__ constructors have been called and executed. The object \u2018t\u2019 calls the constructor of the Teacher class, which transfers the control of the program to the constructor of the Person class. Once the __init__ of Person finishes its execution, the control returns to the constructor of the Teacher class and finishes its execution.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>So, to sum it all up, __init__ is a reserved method for classes in Python that basically behaves as the constructors. In other words, this method in a Python class is used for initialising the attributes of an object. It is invoked automatically at the time of instance creation for a class. This __init__ constructor is invoked as many times as the instances are created for a class. We can use any of the three types of __init__ constructors \u2013 default, parameterised, __init__ with default parameter \u2013 as per the need of our programming module. The \u2018<em>self<\/em>\u2019 is a mandatory parameter for any member function of a class, including the __init__ method, as it is a reference to the instance of the class created.&nbsp;<\/p>\n\n\n\n<p>Even though Python does not support constructor overloading, the concept of constructor overloading can be implemented using the <em>*args <\/em>that are used for passing different numbers of arguments for different objects of a class. Furthermore, we can use the if-else statements for initialising the attributes according to the different types of arguments within the __init__ constructor.&nbsp; To know more about <a href=\"https:\/\/www.mygreatlearning.com\/blog\/classes-and-objects-in-python\/\">Classes and Objects in Python<\/a>, you can check out this blog.<\/p>\n\n\n\n<p>We have also seen how the __init__ method of a class works with inheritance. We can easily call the __init__ method of the base class within the __init__ method of the sub class. When an object for the subclass is created, the __init__ method of the sub class is invoked, which further invokes the __init__ method of the base class.<\/p>\n\n\n\n<p>Mastering the <code>__init__<\/code> method is a major milestone in your journey to writing professional-grade code. But the secret to success is focusing on the fundamentals first. If you try to jump straight into complex data tasks without knowing the basics, it can feel like trying to read a book in a language you haven't learned yet. To build your skills the right way, join our <a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/python-fundamentals-for-beginners\" target=\"_blank\" rel=\"noreferrer noopener\">Free Python Course<\/a>. It\u2019s the easiest way for total beginners to go from zero experience to a confident coder, giving you the exact roadmap you need to master Python and beyond.<\/p>\n\n\n\n<p>Embarking on a journey towards a career in data science opens up a world of limitless possibilities. Whether you\u2019re an aspiring data scientist or someone intrigued by the power of data, understanding the key factors that contribute to success in this field is crucial. For those interested in continuing their learning journey, you can find a variety of <strong><a href=\"https:\/\/www.mygreatlearning.com\/academy\">free courses with certificates<\/a><\/strong> perfect for building new skills in Python and beyond. The below path will guide you to become a proficient data scientist.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-table aligncenter\"><table class=\"has-cyan-bluish-gray-background-color has-background\"><tbody><tr><td><a href=\"https:\/\/www.mygreatlearning.com\/data-science\/courses\/certificates\" target=\"_blank\" rel=\"noreferrer noopener\">Data Science Course Certificates<\/a><\/td><\/tr><tr><td><a href=\"https:\/\/www.mygreatlearning.com\/data-science\/courses\/placements\" target=\"_blank\" rel=\"noreferrer noopener\">Data Science Course Placements<\/a><\/td><\/tr><tr><td><a href=\"https:\/\/www.mygreatlearning.com\/data-science\/courses\/syllabus\" target=\"_blank\" rel=\"noreferrer noopener\">Data Science Course Syllabus<\/a><\/td><\/tr><tr><td><a href=\"https:\/\/www.mygreatlearning.com\/data-science\/courses\/eligibility\" target=\"_blank\" rel=\"noreferrer noopener\">Data Science Course Eligibility<\/a><\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>What is __init__ in Python? In Python, __init__ is a special method known as the constructor. It is automatically called when a new instance (object) of a class is created. The __init__ method allows you to initialize the attributes (variables) of an object. Here's an example to illustrate the usage of __init__: How Does __init__() [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":77962,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36796],"content_type":[36248],"class_list":["post-77921","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-python","content_type-career-guide"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Python __init__:\u00a0An Overview<\/title>\n<meta name=\"description\" content=\"python __init__: In Python, __init__ is a special method known as the constructor.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/python-init\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python __init__:\u00a0An Overview\" \/>\n<meta property=\"og:description\" content=\"python __init__: In Python, __init__ is a special method known as the constructor.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/python-init\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-06-14T04:39:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-14T18:24:36+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/iStock-1411610324.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1576\" \/>\n\t<meta property=\"og:image:height\" content=\"665\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-init\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-init\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"Python __init__:\u00a0An Overview\",\"datePublished\":\"2023-06-14T04:39:17+00:00\",\"dateModified\":\"2024-10-14T18:24:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-init\\\/\"},\"wordCount\":1289,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-init\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/iStock-1411610324.jpg\",\"keywords\":[\"python\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-init\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-init\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-init\\\/\",\"name\":\"Python __init__:\u00a0An Overview\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-init\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-init\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/iStock-1411610324.jpg\",\"datePublished\":\"2023-06-14T04:39:17+00:00\",\"dateModified\":\"2024-10-14T18:24:36+00:00\",\"description\":\"python __init__: In Python, __init__ is a special method known as the constructor.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-init\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-init\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-init\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/iStock-1411610324.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/iStock-1411610324.jpg\",\"width\":1576,\"height\":665,\"caption\":\"python __init__\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-init\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python __init__:\u00a0An Overview\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python __init__:\u00a0An Overview","description":"python __init__: In Python, __init__ is a special method known as the constructor.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/python-init\/","og_locale":"en_US","og_type":"article","og_title":"Python __init__:\u00a0An Overview","og_description":"python __init__: In Python, __init__ is a special method known as the constructor.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/python-init\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2023-06-14T04:39:17+00:00","article_modified_time":"2024-10-14T18:24:36+00:00","og_image":[{"width":1576,"height":665,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/iStock-1411610324.jpg","type":"image\/jpeg"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/python-init\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python-init\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"Python __init__:\u00a0An Overview","datePublished":"2023-06-14T04:39:17+00:00","dateModified":"2024-10-14T18:24:36+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python-init\/"},"wordCount":1289,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python-init\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/iStock-1411610324.jpg","keywords":["python"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/python-init\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/python-init\/","url":"https:\/\/www.mygreatlearning.com\/blog\/python-init\/","name":"Python __init__:\u00a0An Overview","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python-init\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python-init\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/iStock-1411610324.jpg","datePublished":"2023-06-14T04:39:17+00:00","dateModified":"2024-10-14T18:24:36+00:00","description":"python __init__: In Python, __init__ is a special method known as the constructor.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python-init\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/python-init\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/python-init\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/iStock-1411610324.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/iStock-1411610324.jpg","width":1576,"height":665,"caption":"python __init__"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/python-init\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"Python __init__:\u00a0An Overview"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/iStock-1411610324.jpg",1576,665,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/iStock-1411610324-150x150.jpg",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/iStock-1411610324-300x127.jpg",300,127,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/iStock-1411610324-768x324.jpg",768,324,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/iStock-1411610324-1024x432.jpg",1024,432,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/iStock-1411610324-1536x648.jpg",1536,648,true],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/iStock-1411610324.jpg",1576,665,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/iStock-1411610324-640x665.jpg",640,665,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/iStock-1411610324-96x96.jpg",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/iStock-1411610324-150x63.jpg",150,63,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"What is __init__ in Python? In Python, __init__ is a special method known as the constructor. It is automatically called when a new instance (object) of a class is created. The __init__ method allows you to initialize the attributes (variables) of an object. Here's an example to illustrate the usage of __init__: How Does __init__()&hellip;","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/77921","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=77921"}],"version-history":[{"count":32,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/77921\/revisions"}],"predecessor-version":[{"id":117004,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/77921\/revisions\/117004"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/77962"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=77921"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=77921"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=77921"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=77921"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}