Scoping - Formula Sheet
LEGB Scope Resolution Hierarchy
The LEGB rule determines the search priority order for resolving variable references:
| Priority | Scope Type | Description | Example / Location |
|---|---|---|---|
| 1 (Highest) | Local (L) | Variables defined inside the current function or method. | Inside local function block |
| 2 | Enclosed (E) | Variables defined within any enclosing outer functions (nested functions). | Outer function of a nested function block |
| 3 | Global (G) | Variables defined at the top level of the program module. | Top-level script outside all functions |
| 4 (Lowest) | Built-in (B) | Pre-loaded system names and functions imported from libraries. | Built-in modules and keywords |
Class Member Access Modifier Rules
This table summarizes access rules for class members across standard object-oriented languages compared with Python:
| Modifier | C++ and Java Syntax | Python Emulation Convention | Access Permissions |
|---|---|---|---|
| Public | public keyword | Standard variable name (e.g., member) | Accessible from anywhere inside or outside the class. |
| Protected | protected keyword | Single underscore prefix (e.g., _member) | Accessible within the class and its inherited sub-classes. |
| Private | private keyword | Double underscore prefix (e.g., __member) | Accessible strictly within the class itself. Denied outside. |
More for this chapter
Book Back Questions10 textbook MCQs · solved
Additional MCQs15 extra MCQs · solved
Practice TestInteractive · instant score
Book Back TestTest yourself on the textbook set
Additional MCQ TestTest yourself on the extra set
Study NotesConcepts & methods
More chapters in Computer Science
View all
1 Function
2 Data Abstraction
4 Algorithmic Strategies
5 Python -Variables and Operators
6 Control Structures
7 Python functions
8 Strings and String manipulation
9 Lists, Tuples, Sets and Dictionary
10 Python Classes and objects
11 Database Concepts
12 Structured Query Language (SQL)
13 Python and CSV files
14 Importing C++ programs in Python.
15 Data manipulation through SQL
16 Data visualization using pyplot: line chart, pie chart and bar chart