Skip to content

Instantly share code, notes, and snippets.

@IanMcT
Created February 9, 2017 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IanMcT/a0921b27bd6516135e933cad6ecb0b25 to your computer and use it in GitHub Desktop.
Save IanMcT/a0921b27bd6516135e933cad6ecb0b25 to your computer and use it in GitHub Desktop.
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