Computer Science

When is global statement used ? Why is its use not recommended ?

Python Functions

6 Likes

Answer

If we want to assign some value to the global variable without creating any local variable then global statement is used. It is not recommended because once a variable is declared global in a function, we cannot undo the statement. That is, after a global statement, the function will always refer to the global variable and local variable cannot be created of the same name. Also, by using global statement, programmers tend to lose control over variables and their scopes.

Answered By

3 Likes


Related Questions