+ 6

What is __init and __main__ in python

I know that __init__ is a constructor but please explain me what is a contractor with example

11th Oct 2020, 6:00 AM
#It's Tony Stark
#It's Tony Stark - avatar
2 Respostas
+ 7
Maybe you should review the OOP lessons more carefully. A class is a template for an object, it describes what properties and methods an object has. The __init__ method (constructor) is invoked automatically when a new object is created in memory from the class template, usually it assigns instance variables, based on the constructor parameters. https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2467/
11th Oct 2020, 6:12 AM
Tibor Santa
Tibor Santa - avatar
+ 2
__init__ is the class constructor and __main__ is used for : if __name__ == "__main__": #runs as program else: #runs as module
11th Oct 2020, 6:24 AM
ΣΤΕΛΙΟΣ ΚΑΦΑΣ
ΣΤΕΛΙΟΣ ΚΑΦΑΣ - avatar