Advertisement
go6odn28

2_scope_mess

May 1st, 2024
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. #https://softuni.bg/trainings/4371/python-oop-february-2024#lesson-64960
  2. # https://softuni.bg/trainings/resources/video/95524/video-20-february-2024-ines-kenova-python-oop-february-2024/4371   - VIDEO ot 40 min
  3.  
  4.  
  5.  
  6. x = "global"
  7.  
  8.  
  9. def outer():
  10.     x = "local"
  11.  
  12.     def inner():
  13.         nonlocal x
  14.         x = "nonlocal"
  15.         print("inner:", x)
  16.  
  17.     def change_global():
  18.         global x
  19.         x = "global: changed!"
  20.  
  21.     print("outer:", x)
  22.     inner()
  23.     print("outer:", x)
  24.     change_global()
  25.  
  26.  
  27. print(x)
  28. outer()
  29. print(x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement