I'm reading Python sample code
def __init__():
Or
def _variable_hogehoge(x):
I often see it written with two or one underscore like.
Functions defined by two underscores are ** those that do not receive external references **. In this case, enclose it in an underscore. A function defined by one underscore can be referenced **, but basically it seems to be a convention that it is not referenced from the outside **.
I knew so far, but a sentence of this sample code
_, loss_value = sess.run([train_op,loss])
I wondered what the underscore was "[Practice of assigning tapple values not used in Python to“ _ ”(underscore)](http://momijiame.tumblr.com/post/28130976849/python-%E3%81%A7%E4%BD% BF% E3% 82% 8F% E3% 81% AA% E3% 81% 84% E3% 82% BF% E3% 83% 97% E3% 83% AB% E3% 81% AE% E5% 80% A4% E3% 81% AF-% E3% 82% A2% E3% 83% B3% E3% 83% 80% E3% 83% BC% E3% 83% 90% E3% 83% BC-% E3% 81% AB% E4% BB% A3% E5% 85% A5% E3% 81% 99% E3% 82% 8B% E3% 81% A8% E3% 81% 84% E3% 81% 86% E3% 83% 97% E3% 83% A9% E3% 82% AF% E3% 83% 86% E3% 82% A3% E3% 82% B9) "
Well, it's nonsense to assign a variable to an unused return value, so let's ignore it with an underscore.
I feel that it will be beautiful programmatically.
Recommended Posts