![]() ![]() If you're just looking up a variable to read its value, you've got access to global as well as local scope. This is the difference between accessing the name and binding it within a scope. Although I would advise against it since it causes nightmares if something goes wrong or needs debugging. In addition, due to the nature of python, you could also use global to declare functions, classes or other objects in a local context. So the above code will give you: locally defined Me = "locally defined" # Defined locally but declared as global ![]() While if you use the global statement, the variable will become available "outside" the scope of the function, effectively becoming a global variable. ![]() Me = "locally defined" # Defined only in local context The keyword global is only useful to change or create global variables in a local context, although creating global variables is seldom considered a good solution. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |