Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. """ This script showcases the different properties of functions """
  3.  
  4. # Function definitions
  5. def show_str(my_str):
  6. "shows a specified string"
  7. print(my_str)
  8. return
  9.  
  10. def my_age(age=35, my_age_str="My age is "):
  11. "prints a string with an associated age"
  12. print(my_age_str, age)
  13. return
  14.  
  15. def print_all(*args):
  16. "prints all arguments passed to the function"
  17. for arg in args:
  18. print(arg)
  19. return
  20.  
  21. # Running each function
  22.  
  23. # Example 1
  24.  
  25. show_str("Hello World!")
  26.  
  27. # Example 2
  28.  
  29. my_age(my_age_str="My new age is") # Example of keyword arguments | Output: My new age is 35
  30. my_age(age=50) # Output: My age is 50
  31.  
  32. # Example 3
  33. print_all(1, 2, 3, 4, 70) # Output: 1, 2, 3, 4, 70
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement