{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Jupyter Notebooks & Python Tutorial\n", "Shawn Rhoads, Georgetown University (NSCI 526) \n", "\n", "This tutorial has been adapted from the following resources on Jupyter Notebooks and Python:\n", "- Luke Chang's [DartBrains](https://dartbrains.org) \n", "- Adam Pritchard's [Markdown Cheatsheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet)\n", "- Eshin Jolly's [Jupyter Tutorial](https://github.com/Summer-MIND/mind_2018/tree/master/tutorials/jupyter)\n", "- [NumPy Quickstart Tutorial](https://numpy.org/devdocs/user/quickstart.html)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Interactive Coding!\n", "We will use Jupyter Notebooks to interface with Python. Rather than keeping code scripts code and execution separate, jupyter integrates both together using the concept of cells. Two main types of cells are **code cells** and **markdown cells**. Cells pair \"snippets\" of code with the output obtained from running them and can contain plots/figure inline alongside code required to generate them\n", "\n", "**Code cells** contain actual code that you want to run. You can specify a cell as a code cell using the pulldown menu in the toolbar in your Jupyter notebook. Otherwise, you can can hit esc and then y (denoted \"esc, y\") while a cell is selected to specify that it is a code cell. Note that you will have to hit enter after doing this to start editing it. If you want to execute the code in a code cell, hit \"shift + enter.\" Note that code cells are executed in the order you execute them. That is to say, the ordering of the cells for which you hit \"shift + enter\" is the order in which the code is executed. If you did not explicitly execute a cell early in the document, its results are now known to the Python interpreter.\n", "\n", "**Markdown cells** contain text. The text is written in markdown, a lightweight markup language. You can read about its syntax [here](https://daringfireball.net/projects/markdown/syntax). Note that you can also insert HTML into markdown cells, and this will be rendered properly. As you are typing the contents of these cells, the results appear as text. Hitting \"shift + enter\" renders the text in the formatting you specify. You can specify a cell as being a markdown cell in the Jupyter toolbar, or by hitting \"esc, m\" in the cell. Again, you have to hit enter after using the quick keys to bring the cell into edit mode.\n", "\n", "In general, when you want to add a new cell, you can use the \"Insert\" pulldown menu from the Jupyter toolbar. The shortcut to insert a cell below is \"esc, b\" and to insert a cell above is \"esc, a.\" Alternatively, you can execute a cell and automatically add a new one below it by hitting \"alt + enter.\"" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "slideshow": { "slide_type": "subslide" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "10\n" ] } ], "source": [ "# This is a code cell\n", "#Put some code here and get some output below!\n", "x = 10\n", "print(x)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "This is a *markdown* **cell**!" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Notebooks of the Future\n", "Not just for code:\n", "- Markdown, HTML, LateX integration\n", "- Slide shows (like this one!)\n", "- Keep your notes alongside your analysis routines\n", "- Embed images, videos, anything (it's all just HTML + javascript)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "### HTML Integration:\n", "