Skip to content

Commit

Permalink
Automatically backed up by Learn
Browse files Browse the repository at this point in the history
  • Loading branch information
Shortstackm committed Jun 15, 2019
1 parent b449b3d commit 79921d1
Showing 1 changed file with 8 additions and 184 deletions.
192 changes: 8 additions & 184 deletions index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -60,184 +60,12 @@
"### Adding and Deleting Cells"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We have already seen, to alter the contents of a cell we simply double click on that cell, bringing us into insert mode, and then change the contents. Now let's see how to add, and delete cells from escape mode."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Adding cells"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If we wish to quickly add a new cell we can do so with the following steps: \n",
"\n",
"* Make sure we are not in insert mode, but in escape mode\n",
" * *Remember we can tell we are in insert mode when we have a green border around our cell.*\n",
" * To get out of insert mode and into escape mode, press shift + enter. Another option is to press the escape key.\n",
" * You will no longer see a cell bordered in green.\n",
"* Then press the letter `b` to create a new cell."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Deleting cells"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To delete a cell we once again should be in escape mode, and then press the `x` key.\n",
"\n",
"Of course, we'll want a way to undo our deletion. From escape mode, you can press `z` to undo deletion of a cell. Note that this is different from `cmd + z`. Pressing `cmd + z` while in insert mode undoes any changes inside of a cell while, whether these changes be deletions or text insertions. Pressing `z` from escape mode undoes the deletion of a cell.\n",
"\n",
"Go to escape mode and press `x`. This cell disappears!\n",
"\n",
"Then bring it back with `z`."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Types of Cells\n",
"\n",
"The current cell and every other cell in this lesson has been a markdown cell, meaning that it allows us to write text and stylize that text. For example, if you surround some text with stars on either side the text **becomes bold**. That's markdown.\n",
"\n",
"Cells can also have a type of code. If we are writing in a cell that is for Python code, everything in that cell must be valid Python or we will see an error."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"This is a python cell without valid Python so we will see an error"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"So, a cell must either be of type markdown or of type code, in which case all of the contents must be valid Python. It cannot be both. We can quickly change a cell from markdown to code with some keyboard shortcuts.\n",
"\n",
"From escape mode, we change a cell to type code by pressing the letter `y`.\n",
"\n",
"Anytime we create a new cell, say with the shortcut key `b`, the new cell will default to code mode. We can switch to escape mode and press the letter `m` to change the cell from code to markdown."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### View All Shortcuts\n",
"\n",
"Press the key `h` while in escape mode to view the menu for all of Jupyter's shortcuts."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Working with Python in Jupyter"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Ok, now that we know a little bit about adding and deleting cells, as well as changing cell types from markdown to code, let's focus on working with Python in Jupyter. We'll go into a large amount of detail about working with a Jupyter notebook in Python, but the main takeaway is this: if we see a Python cell, we should press `shift + enter` on that cell. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The major gotcha in working with Python code is that we must execute the cells in order for Python to register the code in them. So for example, just seeing the cell where we define `name` to `'bob'` below does not write that cell to memory."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"name = 'bob'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If we try to reference that variable later on without having executed the cell, Python will tell us that it is not defined. "
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'name' 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<ipython-input-4-9bc0cb2ed6de>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mname\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mNameError\u001b[0m: name 'name' is not defined"
]
}
],
"source": [
"name"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To execute or run a cell, we must press `shift + enter` from escape mode on that cell. Upon running a cell, Python will show the the last line of the cell's return value underneath. Let's run the cell below to see this:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"14"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"age = 14\n",
"age"
]
"source": []
},
{
"cell_type": "markdown",
Expand All @@ -250,10 +78,8 @@
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"hometown = 'NYC'"
Expand All @@ -268,7 +94,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 2,
"metadata": {},
"outputs": [
{
Expand All @@ -277,7 +103,7 @@
"'NYC'"
]
},
"execution_count": 4,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -295,10 +121,8 @@
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"None"
Expand Down Expand Up @@ -353,7 +177,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
"version": "3.6.6"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 79921d1

Please sign in to comment.