{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Modes\n", "You have 2 modes:\n", " - command: the cell is highlighted blue \n", " - edit: the cell is highlighted green\n", " \n", "You switch from *command* to *edit* with Enter.\n", "\n", "You switch from *edit* to *command* with Esc." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There are lots of keyboard shortcuts. See the Help menu for a list. There is a command palette accessible with `P` in command mode. There are actually 3 shortcuts for the command palette! `P`, `Cmd/Ctrl+Shift+P`, `Cmd/Ctrl+Shift+F`. The last 2 are useful to open the palette while in edit mode." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Markdown for comments\n", "Cells can contain code or text in Markdown format:\n", "https://www.markdownguide.org/\n", "\n", "This is useful to leave nice comments with your code. You can even use LaTeX formatting for maths equations.\n", "\n", "In *command* mode, you can switch the cell type with `m` or `y`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Why use a notebook?\n", "\n", "1. Nice comments. Useful when learning a language\n", "2. Easy debugging: can run command per command and print all outputs right there! The output will be recorded with the notebook\n", "3. Inline help: we'll see that later once we introduce Python\n", "4. Keeps code and outputs together: easier to remember what code made what figure !" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Inline help\n", "That means you can get some help/documentation on a Python object right here and there, you might not need to flip through web pages.\n", "\n", "You can use `?` in front of a variable to know the type of this variable.\n", "\n", "You can use `tab` on a variable to list all possible methods. Using `tab` on a function call will give you the docstring that lists the purpose of a function and its arguments. " ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "a = \"hello\"" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "?a" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you are not using a notebook, you can access the same help in this way:" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']\n", "\n", "S.count(sub[, start[, end]]) -> int\n", "\n", "Return the number of non-overlapping occurrences of substring sub in\n", "string S[start:end]. Optional arguments start and end are\n", "interpreted as in slice notation.\n" ] } ], "source": [ "print(type(a))\n", "print()\n", "print(dir(a))\n", "print(\"\")\n", "print(a.count.__doc__)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## More than Python\n", "You can do more than Python in a notebook. Notably, notebooks use the IPython Magic commands. We'll see a few in this training. But others can be found here: https://ipython.readthedocs.io/en/stable/interactive/magics.html#\n", "\n", "They allow you to do a lot of different things: time the execution of a line of code or a cell, run an external script, run some code in another language than Python etc." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "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.6.6" } }, "nbformat": 4, "nbformat_minor": 2 }