Advertisement
pleabargain

python 3 the hard way lesson 18 functions

May 4th, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. #Exercise 18: Names, Variables, Code, Functions
  2. #http://learnpythonthehardway.org/book/ex18.html
  3.  
  4. #this one is like argv
  5. def print_two (*args):# never seen * args!
  6.     arg1, arg2 =args
  7.     print ("arg1: {}, arg2: {}".format(arg1, arg2))
  8.  
  9. #ok, that *args is pointless, we can just do
  10. def print_two_again(arg1,arg2):
  11.     print ("arg1: {}, arg2 {}".format(arg1,arg2))
  12.  
  13. #this one takes just one argument
  14. def print_one(arg1):
  15.     print ("arg1: {}".format(arg1))
  16.  
  17. #this takes no arguments
  18. def print_none():
  19.     print ("I got nuthin!")
  20.  
  21. #Now call the functions by naming them and supplying arguments
  22. print_two("D","GD")
  23. print_two_again("me","I")
  24. print_one("first")
  25. print_none()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement