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
  • 107,083
  • 22
  • 201
  • 376
Nachiket
  • 566
  • 1
  • 4
  • 12
  • 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. – Nachiket Nov 16 '20 at 11:14

0 Answers0