Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

difference between local and global variable in python

A global variable is a variable that is accessible globally.
A local variable is one that is only accessible to the current scope,
such as temporary variables used in a single function definition.
Comment

Python Using Global and Local variables in the same code

x = "global "

def foo():
    global x
    y = "local"
    x = x * 2
    print(x)
    print(y)

foo()
Comment

Python Global variable and Local variable with same name

x = 5

def foo():
    x = 10
    print("local x:", x)


foo()
print("global x:", x)
Comment

PREVIOUS NEXT
Code Example
Python :: Python Module Search Path 
Python :: apache virtual host django wsgi 
Python :: como utilizar activar grepper en visual studio code python 
Python :: python herencia clases 
Python :: Modifying a set in Python 
Python :: Regular Expressions In Practical NLP example 
Python :: osmapi 
Python :: python read and write lines in file 
Python :: rich content field django ckeditor not showing bullets 
Python :: Delete file to trash 
Python :: Get index for value_counts() 
Python :: Customize tick spacing 
Python :: what is cls and args in python classmethod 
Python :: django filter form view 
Python :: Horizontal stacked bar chart with annotations 
Python :: disable gpu in jupyter notebook 
Python :: how can i get the n values by space separated with condition in python 
Python :: rich import in python 
Python :: print command in python 
Python :: For_else 
Python :: add all columns in django 
Python :: TypeError: strptime() argument 1 must be str, not list 
Python :: Add value on top of each bar using function 
Python :: python setup specify c++ version 
Python :: import mongodatetime flask 
Python :: python 5 minimal values from array 
Python :: how to add a separator in a menubar pyqt5 
Python :: python lxml get parent 
Python :: how to convert variable in Python ? 
Python :: username__icontains in django 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =