3

Inside the block

if __name__ == "__main__":

do I need to declare a variable as global in order to set its value?
Or... is this block not a function and hence I don't need to do this?

I guess the latter is true but I want to double-check and make sure I understand this better.

peter.petrov
  • 38,363
  • 16
  • 94
  • 159

2 Answers2

4

You just need to declare the variable, global keyword only makes sense in a function.

Jonas Byström
  • 25,316
  • 23
  • 100
  • 147
3
if __name__ == "__main__"

This if statement does not have its own context, therefore variables can be modified without the need for the global keyword.

Eno Gerguri
  • 639
  • 5
  • 22