{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "# Jupyter Notebooks\n", "\n", "- Markdown\n", "- code cells\n", "- kernel" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "
\n", "Jupyter notebooks are a way to combine executable code, code outputs, and text into one connected file.\n", "
\n", "\n", "
\n", "The official documentation from project Jupyter is available \n", "here\n", "and they also have some example notebooks \n", "here\n", ".\n", "
" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Menu Options & Shortcuts\n", "---\n", "\n", "To get a quick tour of the Jupyter user-interface, click on the 'Help' menu, then click 'User Interface Tour'.\n", "\n", "There are also a large number of useful keyboard shortcuts. Click on the 'Help' menu, and then 'Keyboard Shortcuts' to see a list. " ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Cells" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "
\n", "The main organizational structure of the notebook are 'cells'.\n", "
" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "Cells are an independent 'unit'. When you click into a cell, you can 'run' it by clicking Shift + Enter, or by pressing the play (Run) button above. \n", "\n", "Cells come in different types for writing different things - mainly, text or code. " ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "### Markdown Cells\n", "\n", "Cells, can be markdown (text), like this one." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "A brief note about Markdown. It's a way to specify all formatting within the text itself. \n", "\n", "For example, italicized text can be specified with an _underscore_ or *single asterisks*.\n", "\n", "Bold text requires __two underccores__ or **two asterisks**." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "#### Clicker Question #2\n", "\n", "**What does three underscores around text accomplish?**\n", "\n", "- A) bold\n", "- B) italicize\n", "- C) bold + italicize\n", "- D) normal text\n", "- E) I'm lost" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "___you can write your markdown text here to determine the answer to the question___\n" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "### Markdown Headers\n", "\n", "# Headers are specified with a pound sign\n", "\n", "## The more pound signs, the smaller the header\n", "\n", "#### But it's still larger\n", "\n", "than just plain text.\n" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Lists are also possible:\n", " \n", "- item 1\n", "- item 2\n", "- item 3\n", "\n", "\n", "1. numbered item\n", "2. item 2\n", "3. item 3" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "#### Clicker Question #3\n", "\n", "**What would happen if I specified a numbered list but put the same number before each list item?**\n", "\n", "- A) the list would have the same number before each item\n", "- B) markdown would still format it with sequential numbers\n", "- C) markdown wouldn't know it was a list\n", "- D) normal text with everything on a single line\n", "- E) I'm lost" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "test it out down here to see...\n", "\n", "1. list item\n", "1. list item \n", "1. list item" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\\* <- escape character" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "### Code Cells\n", "\n", "Whenever you're writing code, you'll want to be sure the cell is set to be a code cell" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "# Cell can also be code.\n", "a = 1\n", "b = 2" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-1\n" ] } ], "source": [ "# Cells can also have output, that gets printed out below the cell.\n", "c = a - b\n", "print(c)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/plain": [ "-1" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# If you execute a cell with just a variable name in it, it will also get printed\n", "c" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "### Running Cells\n", "\n", "- The numbers in the square brackets to the left of a cell show which cells have been run, and in what order.\n", " - An asterisk (*) means that the cell is currently running\n", " - You do not need to run cells in order! This is useful for flexibly testing and developing code. " ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Coding time\n", "\n", "\n", "Write code that outputs the value '6'" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.5\n" ] }, { "data": { "text/plain": [ "6.0" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "## YOUR CODE HERE\n", "a = 12\n", "b = 1/2\n", "print(b)\n", "c = a * b\n", "\n", "c" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "#### Clicker Question #5\n", "\n", "**Which of the following best describes you?**\n", "\n", "- A) I completed the task.\n", "- B) I tried but wasn't able to complete the task.\n", "- C) I am not sure where to start." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Accessing Documentation" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "
\n", "Jupyter has useful shortcuts. Add a single '?' after a function or class get a window with the documentation, or a double '??' to pull up the source code. \n", "
" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "# For example, execute this cell to see the documentation for the 'abs'\n", "abs?" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Autocomplete" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "
\n", "Jupyter also has \n", "tab complete\n", "capacities, which can autocomplete what you are typing, and/or be used to explore what code is available. (Note: Some of this functionality is limited on datahub.)\n", "
" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "ename": "NameError", "evalue": "name 'ra' 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[1;32m 1\u001b[0m \u001b[0;31m# Move your cursor to the end of the line, press tab, and a drop menu will appear showing all possible completions\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mra\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mNameError\u001b[0m: name 'ra' is not defined" ] } ], "source": [ "# Move your cursor to the end of the line, press tab, and a drop menu will appear showing all possible completions\n", "ra" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "# If there is only one option, tab-complete will auto-complete what you are typing\n", "ran" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Web Browser" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "
\n", "Jupyter notebooks display in a web browser. They are not hosted on the web, everything is happening locally. \n", "
" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "If you click on the url in the browser, you will notice it says 'localhost'. This means it is connected to something locally, on your computer. \n", "\n", "That local connection is to the 'kernel'. " ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Kernels" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "
\n", "The kernel is the thing that executes your code. It is what connects the notebook (as you see it) with the part of your computer that runs code. \n", "
" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "Your kernel also stores your **namespace** - all the variables and code that you have declared (executed). \n", "\n", "It can be useful to clear and re-launch the kernel. You can do this from the 'kernel' drop down menu, at the top, optionally also clearing all ouputs. Note that this will erase any variables that are stored in memory. " ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "skip" } }, "source": [ "
\n", "For more useful information, check out Jupyter Notebooks \n", "tips & tricks\n", ", and more information on how \n", "notebooks work.\n", "
" ] } ], "metadata": { "celltoolbar": "Slideshow", "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.0" }, "rise": { "scroll": true } }, "nbformat": 4, "nbformat_minor": 2 }