Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #These are some global variables, aptly named.
- global_variable = ['That', 'is','global']
- also_global = ' '.join(global_variable) + '.' #Thought I'd try this out. Just read it in DIP.
- print global_variable
- print also_global
- def do_stuff():
- """This is a function that prints out the items in a local list."""
- local_variable = ['This','is','local']
- for item in local_variable:
- print item
- # Calling that function.
- do_stuff()
- def do_more_stuff():
- """This function capitalizes every letter in also_global and calls it out like a cheerleader."""
- for letter in also_global[:-1]:
- if letter == ' ':
- print '\n'
- else:
- print 'Give me a ' + letter.upper()
- print "\n" + also_global[:-1].upper() + '!'
- do_more_stuff()
- def do_things():
- """This function tries to do the same thing with local_variable,
- but it can't, because it doesn't know about it. local_variable is
- only known to do_stuff()."""
- for item in local_variable:
- print item
- # This call will raise a NameError.
- do_things()
Advertisement
Add Comment
Please, Sign In to add comment