Skip to content

video not played or not found error
click on direct switch

Hosted by Dailymotion. For legal issues: Copyright Center · DMC · Instant Removal

Lecture 69: What is the meaning *Scope* of a function in Python Programming

N
Nafees AI Lab

22 Views • May 21, 2025

Description

The scope of a function in Python dictates the visibility and accessibility of variables within the code. It helps prevent naming conflicts and ensures that variables are only accessible where they are needed. Python uses the LEGB rule to determine the scope of a variable:
Local:
Variables defined inside a function are local to that function and cannot be accessed from outside.
Enclosing function locals:
If a function is defined inside another function (nested function), the inner function can access variables from the outer function's scope.
Global:
Variables defined outside any function are global and can be accessed from anywhere in the code.
Built-in:
Python has a set of built-in functions and constants that are always available.