{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Jupyter Python Notebooks\n",
    "Jupyter provides a nice web-based interface to Python. In the below cells you can type a line of Python. For example, here we type in\n",
    "\n",
    "```python\n",
    "a = 5\n",
    "```\n",
    "\n",
    "When we press `SHIFT+Return` this Python line is interpreted interactively"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "a = 5"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To see that this has worked, let's print the value of `a`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n"
     ]
    }
   ],
   "source": [
    "print(a)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can type whatever Python you want, and it will be evaluated interactively. For example..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "b = 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "15\n"
     ]
    }
   ],
   "source": [
    "print(a + b)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "One of the cool things about a Jupyter Python notebook is that you can edit the above cells and re-execute them. For example, change the value of `b` above and re-execute the lines [3] and [4] (by selecting the cell and pressing `SHIFT+Return`."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Another cool thing is that you can mix documentation into your notebook. Do this by selecting a cell and using the dropdown menu to change the cell type to `Markdown`. You can now add documentation, using [markdown](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) formatting. For example, use the hash symbol for headers...\n",
    "\n",
    "# This is a big header\n",
    "\n",
    "## This is a subheading\n",
    "\n",
    "### This is a sub-sub-heading\n",
    "\n",
    "You can add in hyperlinks using square brackets and round brackets, for example [link to course](https://chryswoods.com/python_and_data)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "All of the standard Python help is available from within the notebook. This means that you can type\n",
    "\n",
    "```python\n",
    "help(something)\n",
    "```\n",
    "\n",
    "to get help about `something`. For example, type and execute `help(print)` to get help about the print function..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function print in module builtins:\n",
      "\n",
      "print(...)\n",
      "    print(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False)\n",
      "    \n",
      "    Prints the values to a stream, or to sys.stdout by default.\n",
      "    Optional keyword arguments:\n",
      "    file:  a file-like object (stream); defaults to the current sys.stdout.\n",
      "    sep:   string inserted between values, default a space.\n",
      "    end:   string appended after the last value, default a newline.\n",
      "    flush: whether to forcibly flush the stream.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(print)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can set the name of the notebook by clicking on the name at the top, and setting the name. The notebook is saved to a file called `name.ipynb` (ipynb means 'interactive python notebook'). You can save the notebook using the `File` menu at the top, using `Download as` e.g. saving as a normal Python script, or as a PDF file, webpage or downloading the python notebook itself.\n",
    "\n",
    "You can run this notebook on your own computer by installing Jupyter. More information is available at the [Jupyter website](http://jupyter.org)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Exercise\n",
    "\n",
    "## Exercise 1\n",
    "\n",
    "Use the cells below and to type into the three Python lines\n",
    "\n",
    "```python\n",
    "a = \"Hello\"\n",
    "b = \"World\"\n",
    "print(a,b)\n",
    "```\n",
    "\n",
    "Execute the cells. This should print out `Hello World`.\n",
    "\n",
    "Now go back and change the values of `a` and `b` to `Goodbye` and `Everyone`. Re-execute your cells. This should now print out `Goodbye Everyone`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "a = \"Hello\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "b = \"World\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(a,b)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exercise 2\n",
    "\n",
    "Now change the type of the below cell to `Markdown`. Type in some markdown in this cell and experiment with adding in headings and hyperlinks. Take a look through the [markdown cheat sheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) and see if you can add bullet point lists, images, or code blocks to your cell."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "Here is some markdown\n",
    "\n",
    "### A super subheading\n",
    "\n",
    "* list item 1\n",
    "* list item 2\n",
    "\n",
    "1. numbered list item\n",
    "1. another numbered list item\n",
    "1. another item\n",
    "\n",
    "![Image from the web](https://upload.wikimedia.org/wikipedia/commons/5/52/Angolian-Python.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exercise 3\n",
    "\n",
    "Finally, use the interactive Python help to get help about the `open` function for reading and writing files."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "help(open)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "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.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
