how to access variable of one function in another function in python

def fun1():
    fun1.var = 100
    print(fun1.var)

def fun2():
    print(fun1.var)

fun1()
fun2()

print(fun1.var)

Here is what the above code is Doing:
1. fun1 is defined.
2. fun1.var is defined as 100.
3. fun1 is called.
4. fun1.var is printed.
5. fun2 is defined.
6. fun2 is called.
7. fun1.var is printed.
8. fun1.var is printed.

The output of the above code is:
100
100
100

The reason for this is that fun1.var is a global variable.

When fun1 is called, fun1.var is set to 100.

When fun2 is called, fun1.var is still 100.

When fun1.var is printed, it is still 100.

The reason for this is that global variables are global.

They are not local to a function.

They are defined in the global namespace.

This means that they can be accessed from anywhere in the code.

In the above code, fun1.var is a global variable.

It is defined in the global namespace.

It can be accessed from anywhere in the code.

It is not local to fun1.

It is not local to fun2.

It is global.

Global variables are global.

They are not local to a function.

They are defined in the global namespace.

This means that they can be accessed from anywhere in the code.