What does instantiate mean in the context of this lesson?

I’m struggling to get my head around what the word “instantiate” means, in this context. Can someone try to break down what that term means? And perhaps explain classes a different way, because I’m finding this whole section pretty confusing…

For example, in this exercise it says, “The first dunder method we’re going to use is the __init__ method… This method is used to initialize a newly created object. It is called every time the class is instantiated.”

What does that mean?

It means the class is invoked to create a new instance, an object constructed of the attributes of the class, using the unique values that were passed to the __init__ method as instance variables.

class Foo:
    def __init__(self, bar):
        self.bar = bar

a = Foo('foo')
b = Foo('bar')

a and b above are both instances of the Foo class.

a.bar  =>  foo
b.bar  =>  bar

I was puzzled at this this, too… I searched a little about this and here is my understanding (not 100% sure, though) :
A class is like a set of attributes and methods which everything under the class follows. Think about strings and lists which are also “classes”, it’s just python has created rules for us in advance that each class has its specific “built-in” operations. Now we can create our own classes, we need to give them our own rules. Therefore, we have class variables and methods to set rules for the classes we created. After we defined a certain class, when we want something to be considered as that class we created (again, think about str(), int(), etc) , we need to tell python that “this is SomeClass”, so we “instantiate” it and make it an “instance” of that class so that this something later falls under this class and can be applied with various methods we created in the class block.
Again, this is only my own understanding as a fellow learner and I don’t think it is the exact definition.

Also I have a question, what’s so special about the “dunds” there? The “def” process here seems to be the same as what we learnt in the previous lessons where we just define the methods with any name we want.

Maybe @mtf Roy can check my understanding and answer my question? Thanks in advance.


I think you’ve got a pretty good idea. Anything I add will only muddle your understanding.

Some silliness just to see the mechanics…

>>> class Cap_str:
	def __init__(self, value):
		self.value = value.upper()

>>> a = Cap_str('watermelon')
>>> a.value
>>> type(a)
<class '__main__.Cap_str'>
>>> isinstance(a, Cap_str)

Thank you for asking what I’ve been also struggling with. But still I don’t get what is the purpose of using init specifically, instead of just using other things. @mtf It would be very appreciated if you can help me out with this. Thanks in advance.


Plus I’ve found a nice youtube programming lecture giving clear explanation of the class and object. Hope you find this helpful as well.


The purpose of the __init__() method is to resolve the input parameters into instance attributes (the unique data given to the object).

class Circle:
    def __init__(self, radius):
        self.radius = radius

circle_a = Circle(1)       # instance a
circle_b = Circle(2)       # instance b

print (circle_a.radius)    # 1
print (circle_b.radius)    # 2

Above, circle_a and circle_b are unique instances of the Circle class, and we can see they each have their own radius attribute. self in the above refers to the instance object in context when we poll the attributes or invoke the methods.

from math import pi as PI

class Circle:
    def __init__(self, radius):
        self.radius =  radius
    def circumference(self):
        return 2 * PI * self.radius

circle_a = Circle(1)
circle_b = Circle(2)

print (circle_a.circumference())    # 6.283185307179586
print (circle_b.circumference())    # 12.566370614359172

Note that the last two lines invoke the method with ().

class Circle:
    def __init__(self, radius):
        self.radius =  radius
    def circumference(self):
        return 2 * PI * self.radius
    def area(self):
        return PI * self.radius ** 2

circle_a = Circle(1)
circle_b = Circle(2)

print (circle_a.area())    # 3.141592653589793
print (circle_b.area())    # 12.566370614359172

Thank you! Your examples are really helpful! :slight_smile:


Thanks for this video! We will both learn this eventually!

1 Like

how we could use radius without self in second exmp in area method , based on what I understand
I tested it and got and error :

Traceback (most recent call last):
  File "script.py", line 13, in <module>
    print (circle_a.area())    
  File "script.py", line 8, in area
    return 3.14 * radius ** 2
NameError: name 'radius' is not defined

That is my error. I’ve corrected the example to include self. Sorry about that.

1 Like

very confusing. you always use foo or bar. what is that?

1 Like

Generic names. Nothing more. They still bear the same meaning and represent the same concept. Here, they only represent the concept, not some other abstract.

thanks for recommending this video, I am going through it now including his init method as I am struggling a little bit with the this module! :sweat_smile:

Hi @mtf here your said self.radius =radius, i know the second radius after the assignment operator is the one that we passed as an argument while calling the method(or instantiating a class),
but what about the first one that is self.radius. i though if the class has a variable(attribute) named radius we can link it to that particular instance with the self
but here i dont see any attribute of class Circle with name radius and the code is running fine without any error. can you please explain why.

and i had an other doubt that can we instantiate an object of class in the same class itself? if so how can we do it.

explanation with examples will be more helpful. Thank You.


The attribute name is radius, as in,


self is just the special property that denotes the owner instance, as in a and b above.

1 Like

I myself have had (still have to a certain extend) a hard time wrapping my head around instancing and classes in general. Here is my basic understanding of it so far. I am going to try to explain my understanding of a class in as general real world use case as I can.

I look at a class as a template or recipe to create something. lets take a book for example. How would you describe a book? it need pages, it has an author, it has a release date, it has a genre etc. These descriptions of what defines a book is what we would put in our init() function. So a class would look something like this (I am going to be using python 2 syntax, as I personally feel it makes a little more sense):

class Book(object):

    def __init__(self, title, genre, author, release_date, amount_of_pages):
        self.title = title
        self.genre = genre
        self.author = author
        self.release_date = release_date
        self.amount_of_pages = amount_of_pages

the above example can now be used a template to create a book (a book object). So lets say you had 5 empty books on a table, and you wanted to grab one of them and write your story inside, add you as a author, give it a title etc.

  • book_one
  • book_two
  • book_three
  • book_four
  • book_five

You grabbed book number four. This book is not unique in anyway yet, as its just an blank book looking exactly like the others. How can we make it unique? well we can give it a title, put on an author, add it to a genre and so on… and we can use our defined class for that as follows:

my_book = Book('understanding_classes','programming', 'Jesper Rahlff', '06-06-2020', 200)

notice that the class we defined at the start takes an object? that object is our blank book that we selected (book number four), and every time our code uses the self argument we refer to that specific book (book number four) that we selected.

Once that blank book have been through our template/recipe, its now unique and quite easy to identify on the table amongst the other books (that is still just blank) we did not select. We can even check the unique instance id that belongs to my_book by using


the outcome of all of this is that I have now created a unique book (an instance), which I am the author of, with my chosen title, in my favorite genre.

so why use a class for this stuff instead of just defining some variables like title, genre, author etc?
well in programming its very handy to be able to reuse code. so if I wanted to create 10 books I could now do that with one line of code per book:

my_first_book = Book('understanding_classes','programming', 'Jesper Rahlff', '06-06-2020', 200)
my_second_book = Book('did i really understand classes?','programming', 'Jesper Rahlff', '07-06-2020', 201)
my_third_book = Book('I think I get it','programming', 'Jesper Rahlff', '08-06-2020', 202)

all of these are now unique objects which all used the Book() class as a recipe (is an intance of) to get created.

I hope this helps anyone that is struggling with the concept. This is by no means a perfect understanding of the complete usage of Classes. I am just a fellow learner trying to navigate the world of python .self


:sweat_smile: Hi @saraclick you are not the only struggling with classes hehehe I am struggling too with these…

Hey Everybody

I have watched the following videos. I think when you have watched those two, you will better understand the topics classes, objects and constructors. It was helpful for me.

There are also some videos of him that explains everything how it works in Python. See his Python videos.

I don’t understand this part:
def init(self, diameter):

print("New circle with diameter: {diameter}"**.format(diameter=diameter))**

What is the format part doing here? I am not clear on this syntax and how it works. Could you please explain?

1 Like