Python Local & Global Variables

  

Concept


Global variables are the ones that are defined and declared outside a function and we need to use them inside a function.



Code


Example 1:

def foo():

total = 1
        return total


total = 0
print(foo())

>>> 1


Example 2:

def fun():
        print(s)


s = "Hello World"
fun()

>>> Hello World




Get Help

Comments

Popular posts from this blog

How To Create .ENV File in Python

Create a Large file for Test Data Processing using Python

How to solve the Liner Equation using Python