What do the double __ at the front and back of a variable(?) represent? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What do the double __ at the front and back of a variable(?) represent?

Hi, I'm a new learner and have touched on the basics of python and I am planning to learn both python and C# as I have an end goal I want to reach. I've seen some people who code and write stuff like __main__, __init__ and I'm rather puzzled to what they represent. Any insight in this would be appreciated, thanks! EDIT: I don't know how to post a reply to an answer, but thank you user RedAnt for the response and resources that I can check out!

18th Jul 2016, 8:11 AM
ylyl
1 Answer
+ 1
these are magic methods and they have special functions ( __init__ is called after an object is created). they also can be used to overload operators and define conversions. some of them are explained in section with object oriented programming. you can get some more info about them here http://www.rafekettler.com/magicmethods.html
18th Jul 2016, 8:34 AM
RedAnt
RedAnt - avatar