What does __init__ mean?

There are more than one use for the expression init in Python.

If you see a file named init.py in a directory, it means that directory should be treated as a package (collections of variable, function and class definitions). This can be an empty file, or it can contain initialisation code for the package.

The more likely case you'll encounter it is inside a class, where init() initialises an instance of a class. You will see it defined like this

class MyClass:

    def init(self,a,b,c,d):

        #SOME CODE

What this means is that if you create an instance of a class: MyInstance = MyClass(a,b,c,d), this will run the init function, which will contain initialisation code. This defines what you do with your variables a,b,c,d. Note: self refers to the instance of the class being instantiated, and is implicit (you shouldn't include it when calling MyClass).

Some basic initialisation code could be:

self.a = a

self.b = b

etc.

CW
Answered by Callum W. Python tutor

2052 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

Creating string from multiple strings(or characters)


How do you write code to implement a recursive fibonacci algorithm?


How would you loop over every key and value in a python dictionary?


Create an algorithm that can be used as a guessing game. Make sure to import random at the start.


We're here to help

contact us iconContact ustelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

MyTutor is part of the IXL family of brands:

© 2025 by IXL Learning