0% found this document useful (0 votes)
24 views

What Is Scope in Python?

Scope in Python defines the visibility and lifetime of variables and objects within blocks of code. There are several types of scope including local scope for objects available within a function, global scope for objects available throughout code execution, module-level scope for global objects within a module, and outermost scope for built-in names callable anywhere in a program. Local scope objects can interact with global scope using keywords like global.

Uploaded by

ameetamarwadi
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

What Is Scope in Python?

Scope in Python defines the visibility and lifetime of variables and objects within blocks of code. There are several types of scope including local scope for objects available within a function, global scope for objects available throughout code execution, module-level scope for global objects within a module, and outermost scope for built-in names callable anywhere in a program. Local scope objects can interact with global scope using keywords like global.

Uploaded by

ameetamarwadi
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 1

What is Scope in Python?

Every object in Python functions within a scope. A scope is a block of code where an object
in Python remains relevant. Namespaces uniquely identify all the objects inside a program.
However, these namespaces also have a scope defined for them where you could use their
objects without any prefix. A few examples of scope created during code execution in Python
are as follows:
• A local scope refers to the local objects available in the current function.
• A global scope refers to the objects available throught the code execution since their
inception.
• A module-level scope refers to the global objects of the current module accessible in the
program.
• An outermost scope refers to all the built-in names callable in the program. The objects in
this scope are searched last to find the name referenced.
Note: Local scope objects can be synced with global scope objects using keywords such as global.

You might also like