If __name__=="__main__"

class Obj:
def init(self, a=0, b=1):
self.a = a
self.b = b
if name == “main”:
objects = [Obj(1, 2), Obj(5, 4), Obj(7, 3),
Obj(11, 42), Obj(8, 0), Obj(5, 9)]
what is the use of name == “main”: here
how jupyter notebook knows that current module is main module or imported here?

Hey @Bhawna, when we run file directly from console, lik python abcs.py than the file abcd.py is given name of ‘main’ class, otherwise if any other file has called the function of some other .py file than it will not be named ‘main’. So this is the only way to check if user is trying to run this file direcltly from console or not.

HOpe this resolved your doubt.
Plz mark the doubt as resolved in my doubts section. :blush:

ok so if we will not write this line and call function of some other module then it is guaranteed that code must be executed as their is no check condition.Right??

Hey @Bhawna, yes now you got it right.

Happy Learning :sunny:
Plz mark the doubt as resolved :blush:

ok marked as resolved.