If __name__ == ‘__main__’ Flashcards

1
Q

Why would you use “if __name__ = ‘__main__’

A
  1. Module can be run as a stand alone program
  2. Module can be imported and used by other modules
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does “__name__” work

A

Python sets ‘special variables’, one of which is __name__ then Python will execute the code found within “__main__”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does it mean if the __name__ of the module is __main__

A

That means that the module being used is the one being run directly

How well did you know this?
1
Not at all
2
3
4
5
Perfectly