M
M
Michael S.2021-07-13 18:29:58
Python
Michael S., 2021-07-13 18:29:58

Who can explain in simple terms what "__" means for python?

I constantly meet in classes __init__(). I plunged into the documentation, but due to my lack of knowledge of English, I did not really understand this magic. Please explain in simple terms.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Karbivnichy, 2021-07-13
@BUUSSA

What is the meaning of single and double underscores...

G
galaxy, 2021-07-13
@galaxy

Just the name of the method. The presence of "__" does not give any special properties (I cannot but mention name mangling , although in this case it has nothing to do with it).
Objects in python have a number of special methods (more precisely, property names) that will be called in certain cases of using the object (if, of course, such properties are defined).
__init__called after object creation, usually used to initialize it. And, for example, __str__when converting an object to a string (for example, str(obj)).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question