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

PREVIOUS NEXT
Code Example
Python :: python remove last part of string 
Python :: Python try with else clause 
Python :: how to get ping from computer IN PYTHON 
Python :: df dtype 
Python :: shibang for python file in linux 
Python :: python arabic web scraping 
Python :: Connect to MySQL Using Connector Python C Extension 
Python :: pil saves blue images 
Python :: pandas append new column 
Python :: kivy stuck in fullscreen in jupyter notebook macbook 
Python :: how to capitalize words in python 
Python :: python manage.py collectstatic 
Python :: munshi premchand 
Python :: munshi premchand idgah 
Python :: How to find the most similar word in a list in python 
Python :: python sort() and sorted() 
Python :: spacy import doc 
Python :: python manually trigger exception 
Python :: jupyter notebook not showing all null values 
Python :: round to the nearest 0.5 
Python :: Fibonacci series up to n python 
Python :: figure in matplotlib 
Python :: how to use histogram in python 
Python :: ljust rjust center python 
Python :: django give access to media folder 
Python :: printed in a comma-separated sequence on a single line. 
Python :: how to encode a string in python 
Python :: numpy filter based on value 
Python :: python sum only numbers 
Python :: install pytorch on nvidia jetson nx 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =