InterviewSolution
Saved Bookmarks
| 1. |
What is Scope Resolution in Python? |
|
Answer» Sometimes objects within the same scope have the same name but function differently. In such cases, scope RESOLUTION comes into play in Python automatically. A few examples of such behavior are:
This behavior can be overridden USING the global keyword inside the function, as shown in the following example: temp = 10 # global-scope variabledef func(): global temp temp = 20 # local-scope variable print(temp)print(temp) # output => 10func() # output => 20print(temp) # output => 20 |
|