why does name of local variables start with underscore discouraged?

why does name of local variables start with underscore discouraged? mcq and its answer is provided on this page.

In other words this question is "why are local variable names beginning with an underscore discouraged?"

Local Variable is a variable whose scope is local.

If a variable of same name global variable is defined in a function without global keyword it overrides the global one and becomes local to that function.

why does name of local variables start with underscore discouraged?

Que. why does name of local variables start with underscore discouraged?
a. a) they confuse the interpreter
b. b) they are used to indicate a private variables of a class
c. c) they are used to indicate global variables
d. d) they slow down execution
Answer: b
Explanation : as python has no concept of private variables, leading underscores are used to indicate variables that must not be accessed from outside the class.


Comments