Variable Naming – How and Why to Use Underscores

cnaming-standardspython

If I look in python code and sometimes maybe also in C codes, there is often two variables with the same name except for the underscore. For example two variables

variable1 data;
variable2 _data;

Why is it like that and what is the background?

Best Answer

In general it is to avoid a name clash. You have one variable and you need another which is a different incarnation, possibly in a different domain, yet it calls for the same name.

Like, an application level variable and a system level variable. Or a public property and its internal variable.

Related Topic