typo upd.

This commit is contained in:
Sebastian Raschka 2014-04-29 20:58:41 -04:00
parent 7290f5c862
commit 2587ebf9db

View File

@ -59,7 +59,7 @@
"source": [ "source": [
"## Sections\n", "## Sections\n",
"- [Introduction to namespaces and scopes](#introduction) \n", "- [Introduction to namespaces and scopes](#introduction) \n",
"- [1. LG - Local vs. Global](#section_1) \n", "- [1. LG - Local and Global scopes](#section_1) \n",
"- [2. LEG - Local, Enclosed, and Global scope](#section_2) \n", "- [2. LEG - Local, Enclosed, and Global scope](#section_2) \n",
"- [3. LEGB - Local, Enclosed, Global, Built-in](#section_3) \n", "- [3. LEGB - Local, Enclosed, Global, Built-in](#section_3) \n",
"- [Self-assessment exercise](#assessment)\n", "- [Self-assessment exercise](#assessment)\n",
@ -272,6 +272,13 @@
"<br>" "<br>"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. LG - Local and Global scopes"
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
@ -483,6 +490,26 @@
"<br>" "<br>"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Tip:\n",
"If we want to print out the dictionary mapping of the global and local variables, we can use the\n",
"the functions `global()` and `local()"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print(global()) # prints global namespace\n",
"print(local()) # prints local namespace"
],
"language": "python",
"metadata": {},
"outputs": []
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
@ -979,7 +1006,7 @@
"b = 1\n", "b = 1\n",
"for b in range(5):\n", "for b in range(5):\n",
" if b == 4:\n", " if b == 4:\n",
" print(a, '-> b in for-loop')\n", " print(b, '-> b in for-loop')\n",
"print(b, '-> b in global')" "print(b, '-> b in global')"
], ],
"language": "python", "language": "python",
@ -994,7 +1021,7 @@
] ]
} }
], ],
"prompt_number": 17 "prompt_number": 7
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
@ -1023,7 +1050,7 @@
] ]
} }
], ],
"prompt_number": 14 "prompt_number": 1
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",