+ 1

What does an underscore at the beginning of a variable mean?

I know that variables in all capital letters in any language generally refer to constants, But what does an underscore "_" at the beginning of a variable mean? Ex: _name

7th Aug 2021, 11:10 PM
Imadez
Imadez - avatar
2 Réponses
+ 3
A google search would be better for this than asking here, not going to lie. That said, an underscore, for the most part, doesn't mean anything much other than for code convention purposes. I suppose there is one purpose for it in Python. It's Python's very weird attempt at data hiding. One underscore means that it will name mangle a class variable to be protected, and two will mangle it entirely so it's a private one. Whether you could say that it's effective for data hiding, well, that's debatable. C# does something similar. A google search reveals "...it is used when defining the private member variable for a public property." So there's that.
7th Aug 2021, 11:47 PM
BootInk
BootInk - avatar
+ 2
@BootInk Thank you for your answer. I found this video: https://www.youtube.com/watch?v=ALZmCy2u0jQ&t=23s
8th Aug 2021, 12:02 AM
Imadez
Imadez - avatar