Skip to content

Instantly share code, notes, and snippets.

Created Feb 9, 2017
What would you like to do?
Example of Python program that uses methods and scope of variables.
var1 = 1
var2 = 2
#a method
def my_method():
global var2
var1 = 2
print('Method var1',var1,'var2:',var2)
print('Main: var1',var1,'var2:',var2)
print('Main 2 var1',var1,'var2:',var2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment