daily pastebin goal
24%
SHARE
TWEET

Untitled

a guest Feb 13th, 2018 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Exhibit 4, define function in function. manage to change outer function variable
  2. def send3(rec):
  3.     greeting = "Hi"
  4.    
  5.     def message3(name):
  6.         nonlocal greeting
  7.         greeting = "Hello"
  8.         return(f"{greeting}, {name}")
  9.    
  10.     innerFunc3 = message3(rec)
  11.     print(f"Greeting is: {greeting}")
  12.     return(innerFunc3)
  13.  
  14. res3 = send3("John")
  15. print(type(res3))
  16. print(res3)
  17.  
  18. # Outputs
  19. #    Greeting is: Hello
  20. #    <class 'str'>
  21. #    Hello, John
RAW Paste Data
Top