Guest User

Untitled

a guest
Jul 15th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. 1. In Python, we can define a function **inside** another function.
  2. 2. In Python, a function can be **passed as parameter** to another function
  3. 3. In Python, a function can also **return another function**
  4.  
  5. ```
  6. # A Python program to demonstrate that a function
  7. # can be defined inside another function and a
  8. # function can be passed as parameter.
  9.  
  10. # Adds a welcome message to the string
  11. def messageWithWelcome(str):
  12.  
  13. # Nested function
  14. def addWelcome():
  15. return "Welcome to "
  16.  
  17. # Return concatenation of addWelcome()
  18. # and str.
  19. return addWelcome() + str
  20.  
  21. # To get site name to which welcome is added
  22. def site(site_name):
  23. return site_name
  24.  
  25. print messageWithWelcome(site("GeeksforGeeks"))
  26. ```
  27. Output:
  28. ```
  29. Welcome to GeeksforGeeks
  30. ```
Add Comment
Please, Sign In to add comment