diff --git a/index.ipynb b/index.ipynb index 89886c46aa..5c72861237 100644 --- a/index.ipynb +++ b/index.ipynb @@ -82,7 +82,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Now months later, if we see that string in some code, we may be confused as to what it's about. And when we add more data, this only becomes more difficult. Think of the what we saw in our **Data Types Lab**: `\"art.vandelay@vandelay.co\"`, `\"Ceo\"`, `\"7285553334\"`, `\"vandelay.com\"`. There's a lot to keep track of.\n", + "Now months later, if we see that string in some code, we may be confused as to what it's about. And with more data, this only becomes more difficult. Think of the what we saw in our **Data Types Lab**: `\"art.vandelay@vandelay.co\"`, `\"Ceo\"`, `\"7285553334\"`, `\"vandelay.com\"`. There's a lot to keep track of.\n", "\n", "So let's use a variables to indicate what each of these strings mean." ] @@ -102,14 +102,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "> For this, and all of the subsequent code in gray boxes, you should press shift + enter to ensure that the code executes. If you do not do so with the line above for example, then `email` when we reference `email` in the lines that follow, Jupyter will throw an error indicating that the variable is undefined. So it is not enough to just type the correct code, we need to run shift + enter on our gray boxes to run this code." + "> For this, and all of the subsequent code in gray boxes, you should press shift + enter to ensure that the code executes. If you do not do so with the line above for example, then when we reference `email` in the lines that follow, Jupyter will throw an error indicating that the variable is undefined. So it is not enough to just type the correct code, we need to run shift + enter on our gray boxes to run this code." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "In programming terms, we say that just \"declared a variable `email` and assigned it to the string `\"art.vandelay@vandelay.co\"`\". And to do so, we'll follow the procedure above:\n", + "In programming terms, we say that we just \"declared a variable `email` and assigned it to the string `\"art.vandelay@vandelay.co\"`\". And to do so, we'll follow the procedure above:\n", "\n", "`variable = data`\n", "\n", @@ -209,13 +209,138 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'email' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0memail\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mNameError\u001b[0m: name 'email' is not defined" + ] + } + ], + "source": [ + "email" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Declaring variables without assignment" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We have seen that we can have data without assigning it to variables. " + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Unassigned data'" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"Unassigned data\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Well, sometimes we wish to declare a variable without assigning it to data. In Python, that's a little tricky to do. As we just saw with `email`, declaring variables without assignment throws an error. Well, Python has a special type for us that represents nothing at all." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "None" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "NoneType" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(None)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "None is a data type in Python is represents nothing. So if we do not know the type of a variable and want to have the data to the variable be assigned later, we can assign that variable to equal `None`." + ] + }, + { + "cell_type": "code", + "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ - "email\n" + "address = None" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "And notice that now, `address` is assigned. But it is assigned to `None`." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "address" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Note that when variables are assigned to `None`, pressing shift + enter on the cell block will not output anything below. " ] }, { @@ -462,15 +587,6 @@ "\n", "We also saw that one of the things to pay attention to when working with variables is that they are sometimes different from what we expect. So we just type the name of the variable, to see what it really is and make the change. " ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] } ], "metadata": {