Python, Python Programming, Coding, Web Developer, Code.
this example, we define a global variable x with a value of 1. We then define two functions, foo and bar. foo creates a new variable x with a value of 2 in its local namespace and prints it out. bar uses the global keyword to modify the global variable x and set it to 3. When we call foo, it prints