jprichter

Untitled

Jan 16th, 2012
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. #These are some global variables, aptly named.
  2. global_variable = ['That', 'is','global']
  3. also_global = ' '.join(global_variable) + '.' #Thought I'd try this out. Just read it in DIP.
  4.  
  5. print global_variable
  6. print also_global
  7.  
  8. def do_stuff():
  9.     """This is a function that prints out the items in a local list."""
  10.     local_variable = ['This','is','local']
  11.     for item in local_variable:
  12.         print item
  13.  
  14. # Calling that function.        
  15. do_stuff()
  16.  
  17. def do_more_stuff():
  18.     """This function capitalizes every letter in also_global and calls it out like a cheerleader."""
  19.     for letter in also_global[:-1]:
  20.         if letter == ' ':
  21.             print '\n'
  22.         else:
  23.             print 'Give me a ' + letter.upper()
  24.     print "\n" + also_global[:-1].upper() + '!'  
  25.        
  26. do_more_stuff()
  27.  
  28. def do_things():
  29.     """This function tries to do the same thing with local_variable,
  30.    but it can't, because it doesn't know about it. local_variable is
  31.    only known to do_stuff()."""
  32.     for item in local_variable:
  33.         print item
  34.        
  35. # This call will raise a NameError.
  36. do_things()
Advertisement
Add Comment
Please, Sign In to add comment