Skip to content

Instantly share code, notes, and snippets.

@IanMcT
Created Feb 9, 2017
Embed
What would you like to do?
Example of Python program that uses methods and scope of variables.
#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)
my_method()
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