fork download
  1. # https://i...content-available-to-author-only...e.com/m51fsf
  2. new = []
  3.  
  4. def convert0():
  5. print 'convert0:', new
  6. return new
  7. print 'After convert0:', new
  8.  
  9. def convert1():
  10. new.append(2 % 3 - 1)
  11. print 'convert1:', new
  12. print convert0()
  13. print 'After convert1:', new
  14.  
  15. def convert2():
  16. new.append(3 % 3 - 1)
  17. print 'convert2:', new
  18. convert1()
  19. print 'After convert2:', new
  20.  
  21. """
  22. So while you are correct that return will jump you out of a function, it will not jump you back out of 9 levels of function calls. It only jumps you back to the function's caller, where execution resumes with the next command.
  23. """
  24.  
  25. def convert6():
  26. new.append(7 % 3 - 1)
  27. print 'convert6:', new
  28. convert2()
  29. print 'After convert6:', new
  30.  
  31. print "convert6()", convert6() # <--- prints: None
Success #stdin #stdout 0.01s 7176KB
stdin
Standard input is empty
stdout
convert6() convert6: [0]
convert2: [0, -1]
convert1: [0, -1, 1]
convert0: [0, -1, 1]
[0, -1, 1]
After convert1: [0, -1, 1]
After convert2: [0, -1, 1]
After convert6: [0, -1, 1]
None