What is the purpose of the ‘global’ keyword in Python?

In Python, the global keyword is used to declare a variable as a global variable within a function, allowing the function to access the global variable instead of a local variable. This helps avoid confusion and unexpected behavior by explicitly telling Python that the variable is global.

bannerAds