0

Consider the following code:

def pp():
    print(f'{aa=}')

if __name__ =='__main__':
    aa = 11
    pp()

This prints aa=11. This means pp is getting the value of aa from outside pp. Is there a way to prevent this from happening?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
NNN
  • 697
  • 1
  • 5
  • 15
  • 3
    Does this answer your question? https://stackoverflow.com/questions/31023060/disable-global-variable-lookup-in-python – Axe319 Nov 16 '20 at 10:53
  • 1
    @Axe319 Yes, it does. Thanks. The second answer there is what I was looking for. I'm not sure why it didn't turn up when I was searching. – NNN Nov 16 '20 at 11:14

0 Answers0