{"id":3292,"date":"2020-06-23T16:41:15","date_gmt":"2020-06-23T11:11:15","guid":{"rendered":"http:\/\/www.pythonpool.com\/?p=3292"},"modified":"2026-07-13T12:26:53","modified_gmt":"2026-07-13T06:56:53","slug":"init-python","status":"publish","type":"post","link":"https:\/\/www.pythonpool.com\/init-python\/","title":{"rendered":"Python __init__(): Initialize Objects, Inheritance, and Packages"},"content":{"rendered":"<p><strong>Quick answer:<\/strong> __init__() is the initializer that runs after Python creates an instance. It receives self, prepares instance attributes, and validates starting state. __new__() is the method that creates the object, while __init__.py is a package file with a different purpose. Keep those three names distinct when explaining object construction and imports.<\/p>\n<figure class=\"pythonpool-article-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/init-python.png\" alt=\"Python Pool infographic comparing __new__ object creation __init__ state setup super and __init__.py packages\" width=\"1536\" height=\"1024\" loading=\"lazy\" decoding=\"async\"><figcaption>__new__ creates an instance and __init__ configures it; validate state, call super when required, and distinguish the method from a package&#8217;s __init__.py file.<\/figcaption><\/figure>\n<p>In Python, <code>__init__()<\/code> is the initializer method that usually runs right after an object is created. It receives the new instance as <code>self<\/code> and prepares that instance for normal use.<\/p>\n<p>Python programmers often call <code>__init__()<\/code> a constructor because it is the method people write when they want setup code for a class. More precisely, object creation is handled by <code>__new__()<\/code>, while <code>__init__()<\/code> fills in the instance attributes and checks starting inputs.<\/p>\n<p>The official Python documentation for <a href=\"https:\/\/docs.python.org\/3\/reference\/datamodel.html#object.__init__\">object.__init__<\/a> explains the data model rule. The <a href=\"https:\/\/docs.python.org\/3\/tutorial\/classes.html\">Python classes tutorial<\/a> gives broader class background, and the <a href=\"https:\/\/docs.python.org\/3\/tutorial\/modules.html#packages\">packages tutorial<\/a> plus the <a href=\"https:\/\/docs.python.org\/3\/reference\/import.html#regular-packages\">regular packages reference<\/a> explain the separate <code>__init__.py<\/code> file used by packages.<\/p>\n<p>The two names are easy to mix up: <code>__init__()<\/code> is a method inside a class, while <code>__init__.py<\/code> is a file inside a package directory. They are related by name, but they solve different problems.<\/p>\n<p>Use <code>__init__()<\/code> when each instance needs its own starting data. Keep it focused on setup. If the method opens network connections, reads large files, or does slow work, creating the object becomes surprising and hard to test.<\/p>\n<p>A clean initializer also documents what the class expects at the moment an instance is born. Readers can scan its parameters, see which attributes are created, and understand the minimum data needed for a useful object. That makes later methods easier to follow because the basic object shape is established in one predictable place. Python has one __init__ method per class, so <a href=\"https:\/\/www.pythonpool.com\/python-multiple-constructors\/\">Python Multiple Constructors Guide<\/a> uses default arguments and class methods to provide alternate construction paths.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #990303;color:#990303\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #990303;color:#990303\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/init-python\/#Create_An_Instance_With_init\" >Create An Instance With __init__<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/init-python\/#Validate_Starting_Input\" >Validate Starting Input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/init-python\/#Do_Not_Return_A_Value\" >Do Not Return A Value<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/init-python\/#Handle_Optional_Starting_Data\" >Handle Optional Starting Data<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/init-python\/#Call_Parent_Setup_With_super\" >Call Parent Setup With super()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/init-python\/#Understand_init_py_In_Packages\" >Understand __init__.py In Packages<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/init-python\/#Separate_new_From_init\" >Separate __new__ From __init__<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/init-python\/#Validate_State_At_The_Boundary\" >Validate State At The Boundary<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.pythonpool.com\/init-python\/#Use_Optional_Defaults_Deliberately\" >Use Optional Defaults Deliberately<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.pythonpool.com\/init-python\/#Call_A_Base_Initializer_With_super\" >Call A Base Initializer With super<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.pythonpool.com\/init-python\/#Frequently_Asked_Questions\" >Frequently Asked Questions<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.pythonpool.com\/init-python\/#What_does_init_do_in_Python\" >What does __init__() do in Python?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.pythonpool.com\/init-python\/#Is_init_the_same_as_a_constructor\" >Is __init__() the same as a constructor?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.pythonpool.com\/init-python\/#Can_init_return_a_value\" >Can __init__() return a value?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.pythonpool.com\/init-python\/#What_is_the_difference_between_init_and_init_py\" >What is the difference between __init__ and __init__.py?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Create_An_Instance_With_init\"><\/span>Create An Instance With __init__<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>A class can define <code>__init__()<\/code> to accept inputs and store them on <code>self<\/code>.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">class Profile:\n    def __init__(self, name, role):\n        self.name = name\n        self.role = role\n\n    def label(self):\n        return f\"{self.name}: {self.role}\"\n\nprofile = Profile(\"Ada\", \"admin\")\nprint(profile.label())\n<\/code><\/pre>\n<\/div>\n<p>Calling <code>Profile(\"Ada\", \"admin\")<\/code> creates a new <code>Profile<\/code> instance and passes the arguments to <code>__init__()<\/code> after <code>self<\/code>. You do not pass <code>self<\/code> yourself.<\/p>\n<p>Attributes such as <code>self.name<\/code> belong to the instance. A second profile can have different values without changing the first profile.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Validate_Starting_Input\"><\/span>Validate Starting Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><code>__init__()<\/code> is a good place for small, direct input normalization that every instance should have.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">class Temperature:\n    def __init__(self, celsius):\n        self.celsius = float(celsius)\n\n    def fahrenheit(self):\n        return self.celsius * 9 \/ 5 + 32\n\nreading = Temperature(\"21.5\")\nprint(reading.celsius)\nprint(round(reading.fahrenheit(), 1))\n<\/code><\/pre>\n<\/div>\n<p>This class accepts a string or number and stores a float. The rest of the class can then work with a predictable value.<\/p>\n<p>Keep validation close to the class when all instances must follow the same rule. For heavier parsing, use a class method, factory function, or a separate parser so object setup stays readable.<\/p>\n<p><!-- Python Pool visual layout repair 2026-07-13 --><\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/init-constructor-b143.png\" alt=\"Python Pool infographic showing a Python class, __init__, self, attributes, and a new instance\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Object initialization: A Python class, __init__, self, attributes, and a new instance.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Do_Not_Return_A_Value\"><\/span>Do Not Return A Value<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><code>__init__()<\/code> must return <code>None<\/code>. If it returns another object, Python raises <code>TypeError<\/code>.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">class BadSetup:\n    def __init__(self):\n        return \"ready\"\n\ntry:\n    BadSetup()\nexcept TypeError as error:\n    print(type(error).__name__)\n<\/code><\/pre>\n<\/div>\n<p>The purpose of <code>__init__()<\/code> is to update the instance that already exists. It is not a replacement for a function that computes and returns a result.<\/p>\n<p>If construction needs to choose a different class or reuse an existing object, that belongs in <code>__new__()<\/code> or a factory function, not in <code>__init__()<\/code>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Handle_Optional_Starting_Data\"><\/span>Handle Optional Starting Data<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>When an instance should start with a list, dictionary, or set, build that container inside <code>__init__()<\/code>. This keeps each instance independent.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">class ReadingLog:\n    def __init__(self, owner, books=None):\n        self.owner = owner\n        self.books = list(books or [])\n\n    def add(self, title):\n        self.books.append(title)\n\nlog = ReadingLog(\"Ada\")\nlog.add(\"Fluent Python\")\nprint(log.books)\n<\/code><\/pre>\n<\/div>\n<p>The <code>books=None<\/code> default avoids sharing one list across every instance. A fresh list is created for each <code>ReadingLog<\/code> unless the caller provides starting titles.<\/p>\n<p>This pattern is useful for carts, logs, queues, tags, and other per-object collections. The class owns its starting data, and tests can create a clean instance whenever they need one.<\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/init-inheritance-b143.png\" alt=\"Python Pool infographic mapping a subclass through super, base initialization, and inherited state\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Inheritance flow: A subclass through super, base initialization, and inherited state.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Call_Parent_Setup_With_super\"><\/span>Call Parent Setup With super()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In an inheritance chain, a subclass usually calls <code>super().__init__()<\/code> so the parent class can run its setup first.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">class Account:\n    def __init__(self, email):\n        self.email = email\n\nclass AdminAccount(Account):\n    def __init__(self, email, level):\n        super().__init__(email)\n        self.level = level\n\nadmin = AdminAccount(\"ada@example.com\", 3)\nprint(admin.email, admin.level)\n<\/code><\/pre>\n<\/div>\n<p>Without the <code>super()<\/code> call, <code>AdminAccount<\/code> would skip the setup that stores <code>email<\/code>. That can leave inherited methods with missing attributes.<\/p>\n<p>Keep subclass setup additive when possible: let the parent prepare the shared part, then let the subclass add its own fields. This style is easier to extend than copying parent setup into every child class.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Understand_init_py_In_Packages\"><\/span>Understand __init__.py In Packages<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><code>__init__.py<\/code> is a package file, not a class initializer. It tells Python that a directory is a regular package and can also expose a small public package API.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">from pathlib import Path\nfrom tempfile import TemporaryDirectory\nimport importlib\nimport sys\n\nwith TemporaryDirectory() as root:\n    package = Path(root) \/ \"demo_pkg\"\n    package.mkdir()\n    (package \/ \"__init__.py\").write_text(\"from .helpers import greet\\n\", encoding=\"utf-8\")\n    (package \/ \"helpers.py\").write_text(\n        \"def greet(name):\\n    return f'Hi, {name}'\\n\",\n        encoding=\"utf-8\",\n    )\n\n    sys.path.insert(0, root)\n    try:\n        demo_pkg = importlib.import_module(\"demo_pkg\")\n        print(demo_pkg.greet(\"Ada\"))\n    finally:\n        sys.path.remove(root)\n        sys.modules.pop(\"demo_pkg\", None)\n        sys.modules.pop(\"demo_pkg.helpers\", None)\n<\/code><\/pre>\n<\/div>\n<p>Here <code>__init__.py<\/code> re-exports <code>greet<\/code>, so users can call <code>demo_pkg.greet()<\/code>. In larger packages, keep this file small and predictable. Avoid slow imports or broad side effects during package import.<\/p>\n<p>The practical rule is simple: use <code>__init__()<\/code> inside classes to prepare each instance, use <code>__init__.py<\/code> inside package directories to define package import behavior, and keep both forms focused on lightweight setup.<\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/init-package-b143.png\" alt=\"Python Pool infographic comparing class __init__ methods with package __init__.py exports and import behavior\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Package initializer: Class __init__ methods with package __init__.py exports and import behavior.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Separate_new_From_init\"><\/span>Separate __new__ From __init__<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>For normal classes, Python creates an instance and then calls __init__ to configure it. __new__ matters when customizing creation, especially for immutable subclasses, so most application classes only need __init__.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">class User:\n    def __new__(cls, name):\n        instance = super().__new__(cls)\n        print(\"created\")\n        return instance\n\n    def __init__(self, name):\n        self.name = name\n        print(\"initialized\")\n\nprint(User(\"Ada\").name)\n<\/code><\/pre>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Validate_State_At_The_Boundary\"><\/span>Validate State At The Boundary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>An initializer is a good place to reject impossible values before the object is used. Raise a specific exception and leave the instance in a valid state rather than accepting a value that later methods cannot handle.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">class Port:\n    def __init__(self, value):\n        if not 1 &lt;= value &lt;= 65535:\n            raise ValueError(\"port is outside the valid range\")\n        self.value = value\n\nprint(Port(8000).value)\n<\/code><\/pre>\n<\/div>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/init-check-b143.png\" alt=\"Python Pool infographic testing defaults, required arguments, inheritance order, and object state\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Init checks: Defaults, required arguments, inheritance order, and object state.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Use_Optional_Defaults_Deliberately\"><\/span>Use Optional Defaults Deliberately<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>For optional state, choose a default that cannot be confused with a real value, and avoid mutable defaults in the function signature. Create a new list or dictionary per instance.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">class Cart:\n    def __init__(self, items=None):\n        self.items = list(items) if items is not None else []\n\nfirst = Cart()\nsecond = Cart()\nfirst.items.append(\"book\")\nprint(first.items, second.items)\n<\/code><\/pre>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Call_A_Base_Initializer_With_super\"><\/span>Call A Base Initializer With super<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>When a subclass extends a base class that has initialization work, call super().__init__ with the required arguments. This keeps the base portion of the instance configured instead of silently skipping it.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">class Account:\n    def __init__(self, owner):\n        self.owner = owner\n\n\nclass PremiumAccount(Account):\n    def __init__(self, owner, points=0):\n        super().__init__(owner)\n        self.points = points\n\nprint(PremiumAccount(\"Ada\", 10).__dict__)\n<\/code><\/pre>\n<\/div>\n<p>The Python data model explains the <a href=\"https:\/\/docs.python.org\/3\/reference\/datamodel.html#object.__init__\">object.__init__ and __new__ relationship<\/a>, and the class tutorial shows normal <a href=\"https:\/\/docs.python.org\/3\/tutorial\/classes.html#class-objects\">instance initialization<\/a>. Related references include <a href=\"https:\/\/www.pythonpool.com\/python-super\/\">super()<\/a> and <a href=\"https:\/\/www.pythonpool.com\/python__new__\/\">__new__()<\/a>.<\/p>\n<p>For related object construction and state, compare <a href=\"https:\/\/www.pythonpool.com\/python-super\/\">super()<\/a>, <a href=\"https:\/\/www.pythonpool.com\/python__new__\/\">__new__()<\/a>, and <a href=\"https:\/\/www.pythonpool.com\/python-vars\/\">vars()<\/a> when deciding where initialization and inspection belong.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Frequently_Asked_Questions\"><\/span>Frequently Asked Questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"What_does_init_do_in_Python\"><\/span>What does __init__() do in Python?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>__init__() runs after an instance is created and initializes its attributes or validates the arguments passed to the class constructor.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Is_init_the_same_as_a_constructor\"><\/span>Is __init__() the same as a constructor?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>It is commonly called a constructor, but technically __new__() creates the instance and __init__() initializes the already-created instance.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Can_init_return_a_value\"><\/span>Can __init__() return a value?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>No. __init__() must return None; returning another value raises TypeError during object construction.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"What_is_the_difference_between_init_and_init_py\"><\/span>What is the difference between __init__ and __init__.py?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>__init__ is a class method for instance initialization, while __init__.py is a package file used for package structure and import behavior.<\/p>\n<p><script type=\"application\/ld+json\">{\"@context\":\"https:\/\/schema.org\",\"@type\":\"FAQPage\",\"mainEntity\":[{\"@type\":\"Question\",\"name\":\"What does __init__() do in Python?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"__init__() runs after an instance is created and initializes its attributes or validates the arguments passed to the class constructor.\"}},{\"@type\":\"Question\",\"name\":\"Is __init__() the same as a constructor?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"It is commonly called a constructor, but technically __new__() creates the instance and __init__() initializes the already-created instance.\"}},{\"@type\":\"Question\",\"name\":\"Can __init__() return a value?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"No. __init__() must return None; returning another value raises TypeError during object construction.\"}},{\"@type\":\"Question\",\"name\":\"What is the difference between __init__ and __init__.py?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"__init__ is a class method for instance initialization, while __init__.py is a package file used for package structure and import behavior.\"}}]}<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Understand Python __init__(), object initialization, self, validation, optional state, super(), and the separate role of __init__.py.<\/p>\n","protected":false},"author":3,"featured_media":34222,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[15],"tags":[1065,1045,1048,1043,1040,1044,1049,1060,1052,1051,1053,1058,1042,1055,1050,1046,1062,1066,1041],"class_list":["post-3292","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-__init__-in-python","tag-__init__-python","tag-__init__-python-3","tag-__init__-python-w3","tag-__init__-py-python","tag-__init__-py-python-3","tag-__init__self-args-kwargs-python","tag-def-__init__-python","tag-def-__init__self-python","tag-library-python-__init__","tag-python-__init__","tag-python-__init__-py","tag-python-__init__-py-example","tag-python-__new__-vs-__init__","tag-python-_init_","tag-python-class-__init__","tag-python-def-__init__","tag-python-super-__init__","tag-what-is-__init__-in-python","infinite-scroll-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v28.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Python __init__(): Initialize Objects, Inheritance, and Packages<\/title>\n<meta name=\"description\" content=\"Understand Python __init__(), object initialization, self, validation, optional state, super(), and the separate role of __init__.py.\" \/>\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.pythonpool.com\/init-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python __init__(): Initialize Objects, Inheritance, and Packages\" \/>\n<meta property=\"og:description\" content=\"Understand Python __init__(), object initialization, self, validation, optional state, super(), and the separate role of __init__.py.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/init-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-23T11:11:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-07-13T06:56:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/init-python.png\" \/>\n<meta name=\"author\" content=\"Ashwini Mandani\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"Python Pool\" \/>\n<meta name=\"twitter:description\" content=\"Practical Python tutorials, error fixes, code examples, and project guides.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/init-python.png\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ashwini Mandani\" \/>\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.pythonpool.com\\\/init-python\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/init-python\\\/\"},\"author\":{\"name\":\"Ashwini Mandani\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/person\\\/8a75fb48eb1f3dc952df65a8c28ac056\"},\"headline\":\"Python __init__(): Initialize Objects, Inheritance, and Packages\",\"datePublished\":\"2020-06-23T11:11:15+00:00\",\"dateModified\":\"2026-07-13T06:56:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/init-python\\\/\"},\"wordCount\":1092,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/init-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/python-init-py-package-guide-pythonpool.png\",\"keywords\":[\"__init__ in python\",\"__init__ python\",\"__init__ python 3\",\"__init__ python w3\",\"__init__.py python\",\"__init__.py python 3\",\"__init__(self *args **kwargs) python\",\"def __init__ python\",\"def __init__(self) python\",\"library python __init__\",\"python __init__\",\"python __init__.py\",\"python __init__.py example\",\"python __new__ vs __init__\",\"python _init_\",\"python class __init__\",\"python def __init__\",\"python super().__init__()\",\"what is __init__ in python\"],\"articleSection\":[\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pythonpool.com\\\/init-python\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/init-python\\\/\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/init-python\\\/\",\"name\":\"Python __init__(): Initialize Objects, Inheritance, and Packages\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/init-python\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/init-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/python-init-py-package-guide-pythonpool.png\",\"datePublished\":\"2020-06-23T11:11:15+00:00\",\"dateModified\":\"2026-07-13T06:56:53+00:00\",\"description\":\"Understand Python __init__(), object initialization, self, validation, optional state, super(), and the separate role of __init__.py.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/init-python\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pythonpool.com\\\/init-python\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/init-python\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/python-init-py-package-guide-pythonpool.png\",\"contentUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/python-init-py-package-guide-pythonpool.png\",\"width\":1350,\"height\":650,\"caption\":\"Python __init__ and __init__.py package guide\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/init-python\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pythonpool.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python __init__(): Initialize Objects, Inheritance, and Packages\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#website\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/\",\"name\":\"Python Pool\",\"description\":\"Practical Python tutorials, error fixes, code examples, and project guides.\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pythonpool.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/aa.png\",\"contentUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/pythonpool\",\"https:\\\/\\\/www.youtube.com\\\/c\\\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/person\\\/8a75fb48eb1f3dc952df65a8c28ac056\",\"name\":\"Ashwini Mandani\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f765ed1940ac0ae1d30ce4cb2f1452c1e83143b07354d25a42c1cd118980e269?s=96&d=wavatar&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f765ed1940ac0ae1d30ce4cb2f1452c1e83143b07354d25a42c1cd118980e269?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f765ed1940ac0ae1d30ce4cb2f1452c1e83143b07354d25a42c1cd118980e269?s=96&d=wavatar&r=g\",\"caption\":\"Ashwini Mandani\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python __init__(): Initialize Objects, Inheritance, and Packages","description":"Understand Python __init__(), object initialization, self, validation, optional state, super(), and the separate role of __init__.py.","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.pythonpool.com\/init-python\/","og_locale":"en_US","og_type":"article","og_title":"Python __init__(): Initialize Objects, Inheritance, and Packages","og_description":"Understand Python __init__(), object initialization, self, validation, optional state, super(), and the separate role of __init__.py.","og_url":"https:\/\/www.pythonpool.com\/init-python\/","og_site_name":"Python Pool","article_published_time":"2020-06-23T11:11:15+00:00","article_modified_time":"2026-07-13T06:56:53+00:00","og_image":[{"url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/init-python.png","type":"","width":"","height":""}],"author":"Ashwini Mandani","twitter_card":"summary_large_image","twitter_title":"Python Pool","twitter_description":"Practical Python tutorials, error fixes, code examples, and project guides.","twitter_image":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/init-python.png","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Ashwini Mandani","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pythonpool.com\/init-python\/#article","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/init-python\/"},"author":{"name":"Ashwini Mandani","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/8a75fb48eb1f3dc952df65a8c28ac056"},"headline":"Python __init__(): Initialize Objects, Inheritance, and Packages","datePublished":"2020-06-23T11:11:15+00:00","dateModified":"2026-07-13T06:56:53+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pythonpool.com\/init-python\/"},"wordCount":1092,"commentCount":0,"publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/www.pythonpool.com\/init-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-init-py-package-guide-pythonpool.png","keywords":["__init__ in python","__init__ python","__init__ python 3","__init__ python w3","__init__.py python","__init__.py python 3","__init__(self *args **kwargs) python","def __init__ python","def __init__(self) python","library python __init__","python __init__","python __init__.py","python __init__.py example","python __new__ vs __init__","python _init_","python class __init__","python def __init__","python super().__init__()","what is __init__ in python"],"articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pythonpool.com\/init-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pythonpool.com\/init-python\/","url":"https:\/\/www.pythonpool.com\/init-python\/","name":"Python __init__(): Initialize Objects, Inheritance, and Packages","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pythonpool.com\/init-python\/#primaryimage"},"image":{"@id":"https:\/\/www.pythonpool.com\/init-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-init-py-package-guide-pythonpool.png","datePublished":"2020-06-23T11:11:15+00:00","dateModified":"2026-07-13T06:56:53+00:00","description":"Understand Python __init__(), object initialization, self, validation, optional state, super(), and the separate role of __init__.py.","breadcrumb":{"@id":"https:\/\/www.pythonpool.com\/init-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pythonpool.com\/init-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/init-python\/#primaryimage","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-init-py-package-guide-pythonpool.png","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-init-py-package-guide-pythonpool.png","width":1350,"height":650,"caption":"Python __init__ and __init__.py package guide"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pythonpool.com\/init-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"Python __init__(): Initialize Objects, Inheritance, and Packages"}]},{"@type":"WebSite","@id":"https:\/\/www.pythonpool.com\/#website","url":"https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Practical Python tutorials, error fixes, code examples, and project guides.","publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/pythonpool","https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/8a75fb48eb1f3dc952df65a8c28ac056","name":"Ashwini Mandani","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/f765ed1940ac0ae1d30ce4cb2f1452c1e83143b07354d25a42c1cd118980e269?s=96&d=wavatar&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f765ed1940ac0ae1d30ce4cb2f1452c1e83143b07354d25a42c1cd118980e269?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f765ed1940ac0ae1d30ce4cb2f1452c1e83143b07354d25a42c1cd118980e269?s=96&d=wavatar&r=g","caption":"Ashwini Mandani"}}]}},"_links":{"self":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/3292","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=3292"}],"version-history":[{"count":21,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/3292\/revisions"}],"predecessor-version":[{"id":41368,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/3292\/revisions\/41368"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/34222"}],"wp:attachment":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=3292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=3292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=3292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}