v=5 code = """def myFun(): global v v=10 print 'This is my function' """ exec code print v myFun() #must execute the code before calling function print v
Output:
5 This is my function 10
v=5 code = """def myFun(): global v v=10 print 'This is my function' """ exec code print v myFun() #must execute the code before calling function print v
5 This is my function 10
0 comments:
Post a Comment