A local variable is a variable that is defined within a specific function and is only accessible within that function. It cannot be accessed by other functions within the program.
In contrast, a global variable is a variable that is declared outside of any function, allowing it to be accessed by all functions in the program
g=4 #global variable def func_multiply(): l=5 #local variable m=g*l return m func_multiply()
Output: 20
If you attempt to access the local variable outside the func_multiply function, you will encounter an error.
Leave a Reply