how to create a python global variable
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
x = “awesome”
def myfunc():
x = “fantastic”
print(“Python is “ + x)
myfunc()
print(“Python is “ + x)
thank you very much
A variable converts local only if you put it inside a function and all other which are outside of functions are global variables
Create a Global Variable x = “global” def foo(): print(“x inside:”, x) foo() print(“x outside:”, x) Output. x inside: global x outside: global
print