Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. In Python, we can define a function **inside** another function.
- 2. In Python, a function can be **passed as parameter** to another function
- 3. In Python, a function can also **return another function**
- ```
- # A Python program to demonstrate that a function
- # can be defined inside another function and a
- # function can be passed as parameter.
- # Adds a welcome message to the string
- def messageWithWelcome(str):
- # Nested function
- def addWelcome():
- return "Welcome to "
- # Return concatenation of addWelcome()
- # and str.
- return addWelcome() + str
- # To get site name to which welcome is added
- def site(site_name):
- return site_name
- print messageWithWelcome(site("GeeksforGeeks"))
- ```
- Output:
- ```
- Welcome to GeeksforGeeks
- ```
Add Comment
Please, Sign In to add comment