del_local.py 377 B

12345678910111213141516171819202122232425
  1. # delete local then try to reference it
  2. def f():
  3. x = 1
  4. y = 2
  5. print(x, y)
  6. del x
  7. print(y)
  8. try:
  9. print(x)
  10. except NameError:
  11. print("NameError");
  12. f()
  13. # delete local then try to delete it again
  14. def g():
  15. x = 3
  16. y = 4
  17. print(x, y)
  18. del x
  19. print(y)
  20. try:
  21. del x
  22. except NameError:
  23. print("NameError");
  24. g()