The scope of a variable in Python refers to the part of the code where it can be accessed. There are two main types of variable scope in Python: global scope and local scope.
A variable with global scope can be accessed from anywhere in the code, including within functions. A variable with local scope can only be accessed within the function or block of code where it is defined.
When a variable is defined within a function or block of code, it has local scope by default. However, you can make a variable have global scope by using the `global` keyword before the variable name.
x = 10
x = 20
In this example, the global keyword is used to make the variable x have global scope within the function my_function(). This allows the function to modify the value of the global variable x. The final print() statement outputs the value 20, which was assigned to x by the function.