{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "Environmental Data Analytics | John Fay and Luana Lima | Developed by Kateri Salk \n", "Spring 2023\n", "\n", "---\n", "\n", "# 1: Coding Basics\n", "\n", "### Lesson Objectives\n", "- Examine where Python code can be written and run\n", " - IPython & Jupyter Notebooks\n", " - Integrated Development Environments (IDEs): Spyder\n", "- Review the basic elements of Python code:\n", " - Basic Python syntax: whitespace, comments, variable naming\n", " - Fundamental data types: numbers, strings, lists/tuples, sets, dictionaries\n", " - Python functions and methods\n", " - Getting help in Python" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Tour of Jupyter Notebooks\n", "Jupyter Notebooks are similar to R Markdown documents in that they include both formatted text and code. Jupyter Notebooks are quite powerful, but we haven't the time to fully explore them. Instead, I'll refer you to [Jupyter's documentation](https://jupyter.readthedocs.io/en/latest/index.html) to learn more and instead focus on what we need to know to use Jupyter to learn Python. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Creating your Jupyter environment\n", "First, we'll be using Jupyter installed in one of Duke's \"virtual containers\". \n", "* Navigate to https://cmgr.oit.duke.edu/containers and log in.\n", "* Find and click the button to (`reserve Jupyter`)[https://cmgr.oit.duke.edu/containers/Jupyter].\n", "\n", "***→This adds the Jupyter container to the list of your reservations. This container will persist for the remainder of the semester and all your work will be saved on this virtual machine. You can return to it from any web browser using the link above!***" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### The Jupyter Console\n", "The Jupyter Console is a sort of file manager. You'll see folders and some files with an `.ipynb` extension. Those files are Jupyter notebooks. Let's explore how these notebook files are used an managed. \n", "\n", "##### Opening an existing document\n", "* Click on the `ggplot-python.ipynb` file. The notebook opens in a new tab. \n", "* Go back to the browser tab for the Jupyter console. Note that the `ggplot-python.ipynb` notebook is a different color. *This means that the kernel for that notebook is running. Even if you close the web page for that notebook, it remains \"running\" meaning all variables continue to be saved.* \n", "* Select the running notebook, then click the `Shutdown` button. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### Creating a new notebook\n", "* From the Jupyter Console, select the `New ▼` dropdown, then select Python 3. \n", "* In the new document that appears, rename it `MyFirstNotebook`\n", "* Save it\n", "* Add a `print (\"Hello World\")` in the code block. \n", "* Run the code by clicking the `►|` button. \n", "\n", "**There, you've run a python command!** We'll learn more about Jupyter as we dig deeper into Python.\n", "\n", "---" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.11.0" } }, "nbformat": 4, "nbformat_minor": 4 }