{ "metadata": { "name": "notebook_practice" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "IPython Notebook practice\n", "=========================\n", "\n", "Your next step is to learn how to use the IPython Notebook to run Python right here inside your browser. A Notebook is made of *cells*; some are text cells, like this one (Notebook calls them \"Markdown\" cells). The cell below this is a *code* cell that can run Python commands. In fact, it's waiting for you to run it right now!\n", "\n", "Click your mouse in the cell below this one. To tell the Notebook to execute that code, hold down `SHIFT` and hit `Enter`." ] }, { "cell_type": "code", "collapsed": false, "input": [ "print \"Hello, Student!\"" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the next cell, try typing some code of your own. Type\n", "\n", " for food in [\"milk\", \"bread\", \"ugli fruit\"]:\n", " print food\n", "\n", "and hit `SHIFT`+`Enter`.\n", "\n", "Notice that the code didn't execute when you hit `Enter` at the end of typing the first line. The notebook waits for `SHIFT`+`Enter` to execute the code." ] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can always go back and modify old cells. Click back in the cell *above* this one, change `\"bread\"` to `\"rice\"`, and use `SHIFT`+`Enter` to execute it again.\n", "\n", "Saving your work\n", "----------------\n", "\n", "At the top of this page, there's a menu bar and a series of icons. Hover your mouse over the icons to see what they do. The only one you really need to learn now, though, is the one on the far left - the *save* icon (or File / Save from the menu). The IPython Notebook *does not autosave!* - so if you close this webpage down without saving, you'll lose all the work you've done on it! We think you'll want to keep it instead to refer to in the future. (If you actually want a fresh start, you can choose Cell / All Output / Clear from the menus.)\n", "\n", "How to cheat\n", "------------\n", "\n", "One wonderful thing about the IPython Notebook is that *it helps you cheat*. If you're in the middle of typing *anything* in a Notebook cell and you hit the `Tab` key, a dropdown list will appear with what IPython thinks you might want to type next. This can help you remember Python commands, variable names, etc., especially if you can remember the first letter.\n", "\n", "In the cell below, type `pr` and then hit `Tab`. Choose `print` from the dropdown list that appears. Then type ` 'yay for TAB!'` and hit `SHIFT`+`Enter`." ] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Tab completion can also show you what methods an object has. We haven't taught you those words yet, so I'm talking nonsense. But try this out now anyway, and later in the weekend it will be handy to you.\n", "\n", "Go to the next cell down and hit `SHIFT`+`Enter`. Now IPython knows about your variable `x`. Now go to the cell below that, put your cursor right after the period in `x.`, and hit `Tab`. A list of possible things you can do to `x` appears (really, they're things `x` can do to *itself* when you tell it to). Choose the first one, `capitalize`. Type `()` (open and close parentheses) immediately after it, so the whole thing looks like\n", "\n", " x.capitalize()\n", "\n", "and hit `SHIFT`+`Enter`." ] }, { "cell_type": "code", "collapsed": false, "input": [ "x = \"big\"" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "x." ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Nice, huh? You didn't even know the `capitalize` method existed, but IPython showed it to you.\n", "\n", "Success!\n", "========\n", "\n", "You've seen the mechanics of working with the IPython Notebook. Now it's time to work through the tutorial. \n", "\n", "Save this page (remember the icon at the top left), then close it, and choose \"day1.1\" from the list of notebooks on your IPython Dashboard. Have fun and ask lots of questions!" ] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }