Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Python Fundamentals

Lesson 12 of 55 · Python

Scope and Namespace

Duration: 20 minutes

Scope and Namespace\n\nPython follows the LEGB rule to resolve names: Local → Enclosing → Global → Built‑in. Understanding this helps you avoid accidentally shadowing variables.\n\npython\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

Previous: Lambda FunctionsNext: Data Structures – Lists