Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

accessing a variable from outside the function in python

# for accessing a variable from outside the function then create that variable
# as an attribute of the function
def hi():
    # other code...
    hi.bye = 42  # Create function attribute.
    sigh = 10

hi()
print(hi.bye)  # -> 42
Comment

PREVIOUS NEXT
Code Example
Python :: are tuples in python mutable 
Python :: target encoder sklearn example 
Python :: how to sort values in python 
Python :: run multiprocesses on flask 
Python :: jupyter notebook bold text 
Python :: dict comprehension python 
Python :: read variable in a string python 
Python :: python how to iterate through a list of lists 
Python :: how to draw dendrogram in python 
Python :: percent sign in python 
Python :: python find dir 
Python :: sorted python 
Python :: python flatten a list of lists 
Python :: * pattern by python 
Python :: numpy index of first true value 
Python :: python how to make boxplots with swarmplot 
Python :: Time series missing values 
Python :: infinite while loop in python 
Python :: get value of 1 field in model django 
Python :: python convert string to float 
Python :: get midnight of current day python 
Python :: xlabel not showing matplotlib 
Python :: loop in python 
Python :: open multiple plots python 
Python :: python inline if 
Python :: jupyter notebook not opening 
Python :: python Using for loop and list comprehension 
Python :: Python NumPy append Function Example Appending arrays 
Python :: simple python game code 
Python :: python list with several same values 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =