Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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
 
PREVIOUS NEXT
Tagged: #accessing #variable #function #python
ADD COMMENT
Topic
Name
4+8 =