legb scope tutorial

This commit is contained in:
Sebastian Raschka 2014-04-28 21:50:35 -04:00
parent c4f0cc8bea
commit 19ae86ab1a

View File

@ -41,7 +41,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"This is a short tutorial about Python's scope resolution for variable names using the LEGB-rule. The following section will have short example code blocks that should illustrate the problem followed by short explanations. You can simply read it from start to end, but I'd recommend you to execute the code snippets yourself by copy & paste, or by directly [downloading this IPython notebook](https://github.com/rasbt/python_reference/raw/master/python_true_false.ipynb)."
"This is a short tutorial about Python's scope resolution for variable names using the LEGB-rule. The following section will have short example code blocks that should illustrate the problem followed by short explanations. You can simply read it from start to end, but I'd recommend you to execute the code snippets yourself by copy & paste, or by directly [downloading this IPython notebook](https://github.com/rasbt/python_reference/tutorials/raw/master/scope_resolution.ipynb)."
]
},
{
@ -59,10 +59,10 @@
"source": [
"## Sections\n",
"- [Introduction to namespaces and scopes](#introduction) \n",
"- [1. LG - Local vs. Global](section_1) \n",
"- [2. LEG - Local, Enclosed, and Global scope](section_2) \n",
"- [3. LEGB - Local, Enclosed, Global, Built-in](section_3) \n",
"- [Conclusion](conclusion) \n",
"- [1. LG - Local vs. Global](#section_1) \n",
"- [2. LEG - Local, Enclosed, and Global scope](#section_2) \n",
"- [3. LEGB - Local, Enclosed, Global, Built-in](#section_3) \n",
"- [Conclusion](#conclusion) \n",
"- [Solutions](#solutions)"
]
},
@ -122,6 +122,15 @@
"According to the LEGB-rule, Python looks for an object through the namespaces in the following order L -> E -> G -> B: If a variable name is not found in the local namespaces, the namespaces of the enclosed scope are being searched, and if the variable name is also not defined here, the global namespaces come next and so forth."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<a name=\"section_1\"></a>\n",
"<br>\n",
"<br>"
]
},
{
"cell_type": "markdown",
"metadata": {},
@ -330,6 +339,15 @@
"<br>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<a name=\"section_2\"></a>\n",
"<br>\n",
"<br>"
]
},
{
"cell_type": "markdown",
"metadata": {},
@ -433,6 +451,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"<a name=\"section_3\"></a>\n",
"<br>\n",
"<br>"
]