Answers for "python edit global variable in function"

0

python edit global variable in function

globalvar = "flower"

def editglobalvar():
	global globalvar # accesses the "globalvar" variable, so when we change it
    # it won't assign the new value to a local variable,
    # not changing the value of the global variable
    
    globalvar = "good" # assigning new value
    
print(globalvar) # outputs "flower"
# if we didnt use the "global" keyword in the function, it would print out 
# "flower"
Posted by: Guest on July-24-2021
1

how to set global variable in python function

#A global variable can be accessed from the hole program.

global var = "Text"
Posted by: Guest on August-05-2021

Python Answers by Framework

Browse Popular Code Answers by Language