---
title: "What is Python __init__()?"  
description: "What is Python __init__()?"  
author: "Jk Malhotra"  
published: 2025-10-23  
updated: 2025-10-23  
canonical: https://www.mindstick.com/interview/34394/what-is-python-__init__  
category: "python"  
tags: ["python-3.4", "Python 3"]  
reading_time: 4 minutes  

---

# What is Python __init__()?

> The `__init__()` method is a **special method (also called a “dunder” method)** in Python classes.\
> It automatically runs **every time you create a new object** from a class.

- It is [known as the **constructor**](https://www.mindstick.com/forum/161934/explain-the-python-classes-and-objects-with-example) (short for “initializer”).
- It’s used to **initialize object attributes** — i.e., set up the object with specific data when it’s created.

## Basic Example

```python
class Person:
    def __init__(self, name, age):  # constructor
        self.name = name            # instance attribute
        self.age = age

# create object (this calls __init__ automatically)
p1 = Person("Alice", 25)
p2 = Person("Bob", 30)

print(p1.name)   # Alice
print(p2.age)    # 30
```

When you call `Person("Alice", 25)`, Python does this behind the scenes:

- Creates a new empty `Person` object in memory.
- Calls `__init__(p1, "Alice", 25)` to initialize it.
- Returns the fully constructed object.

## What is `self`?

> The `self` parameter refers to the **current instance (object)** being created. You must include it as the **first parameter** in any instance method, including `__init__()`. It lets you store data on that specific object.

## Example:

```python
class Dog:
    def __init__(self, name):
        self.name = name   # binds the value to the object

dog1 = Dog("Buddy")
dog2 = Dog("Max")

print(dog1.name)   # Buddy
print(dog2.name)   # Max
```

Each dog keeps its own `name` value because of `self`.

## Default and Optional Parameters

You can give parameters default values, just like with normal functions.

```python
class Car:
    def __init__(self, brand, color="white"):
        self.brand = brand
        self.color = color

c1 = Car("Toyota", "red")
c2 = Car("Honda")  # uses default color

print(c1.color)  # red
print(c2.color)  # white
```

## `init()` vs Normal Methods

| Feature | `__init__()` | Normal Method |
| --- | --- | --- |
| Called automatically? | Yes (on object creation) | No (you call it manually) |
| Purpose | Initialize object attributes | Perform actions on an object |
| Returns | [Always `None`](https://www.mindstick.com/interview/34392/explain-the-python-none) | Can return values |

##

## Answers

### Answer by Jk Malhotra

> The `__init__()` method is a **special method (also called a “dunder” method)** in Python classes.\
> It automatically runs **every time you create a new object** from a class.

- It is [known as the **constructor**](https://www.mindstick.com/forum/161934/explain-the-python-classes-and-objects-with-example) (short for “initializer”).
- It’s used to **initialize object attributes** — i.e., set up the object with specific data when it’s created.

## Basic Example

```python
class Person:
    def __init__(self, name, age):  # constructor
        self.name = name            # instance attribute
        self.age = age

# create object (this calls __init__ automatically)
p1 = Person("Alice", 25)
p2 = Person("Bob", 30)

print(p1.name)   # Alice
print(p2.age)    # 30
```

When you call `Person("Alice", 25)`, Python does this behind the scenes:

- Creates a new empty `Person` object in memory.
- Calls `__init__(p1, "Alice", 25)` to initialize it.
- Returns the fully constructed object.

## What is `self`?

> The `self` parameter refers to the **current instance (object)** being created. You must include it as the **first parameter** in any instance method, including `__init__()`. It lets you store data on that specific object.

## Example:

```python
class Dog:
    def __init__(self, name):
        self.name = name   # binds the value to the object

dog1 = Dog("Buddy")
dog2 = Dog("Max")

print(dog1.name)   # Buddy
print(dog2.name)   # Max
```

Each dog keeps its own `name` value because of `self`.

## Default and Optional Parameters

You can give parameters default values, just like with normal functions.

```python
class Car:
    def __init__(self, brand, color="white"):
        self.brand = brand
        self.color = color

c1 = Car("Toyota", "red")
c2 = Car("Honda")  # uses default color

print(c1.color)  # red
print(c2.color)  # white
```

## `init()` vs Normal Methods

| Feature | `__init__()` | Normal Method |
| --- | --- | --- |
| Called automatically? | Yes (on object creation) | No (you call it manually) |
| Purpose | Initialize object attributes | Perform actions on an object |
| Returns | [Always `None`](https://www.mindstick.com/interview/34392/explain-the-python-none) | Can return values |

##


---

Original Source: https://www.mindstick.com/interview/34394/what-is-python-__init__

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
