Lesson 12 of 55 · Python
Scope and Namespace
Duration: 20 minutes
Lesson 12 of 55 · Python
Duration: 20 minutes
python\ncount = 0 # Global\n\ndef outer():\n count = 1 # Enclosing\n def inner():\n count = 2 # Local\n print('inner count:', count)\n inner()\n print('outer count:', count)\n\nouter()\nprint('global count:', count)\n\n\nRunning the script prints 2, 1, and 0, demonstrating each scope in action.\n