Python - Namespaces and Function Variable Scope with Code Examples - Python for Beginners APPFICIAL

Python - Namespaces and Function Variable Scope with Code Examples - Python for Beginners APPFICIAL

Appficial

2 года назад

1,512 Просмотров

A namespace is used by the python interpreter to track all objects in your program. It maps variable names to their corresponding object. There are local and global variable namespaces. Global variables are tracked in the global namespace, and local variables are tracked in the local namespace.

Variables have a scope, which is where the variable is visible.
Local variable - a variable created inside a function, where the scope is in the currently executing function
- Global variable – a variable created outside a function, where the scope is the entire program
- Global variables can only be updated with a global statement
Built-in scope – contains Python built-in names like int(), str(), list(), range(), etc.

You can see the names in the current local and global namespace by using the locals() and globals() built-in functions.



Subscribe to Appficial for more programming videos coming soon. Also, don't forget to click LIKE and comment on the video if it helped you out!

Тэги:

#appficial #python #python_scope #python_namespace #python_variable_scope #python_locals() #python_globals() #locals() #globals() #variable_scope #scope #python_function #python_functions #functions #python_function_code #calling_a_function #defining_a_function #intro_to_python #python_programming #python_code #learn_python #python_tutorial #python_for_beginners #python_coding #python_course #python_lectures #function_call #python_for_kids #stem_coding
Ссылки и html тэги не поддерживаются


Комментарии: