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!
Click your mouse in the cell below this one. To tell the Notebook to execute that code, hold down SHIFT
and hit Enter
.
print "Hello, Student!"
In the next cell, try typing some code of your own. Type
for food in ["milk", "bread", "ugli fruit"]:
print food
and hit SHIFT
+Enter
.
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.
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.
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.)
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.
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
.
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.
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
x.capitalize()
and hit SHIFT
+Enter
.
x = "big"
x.
Nice, huh? You didn't even know the capitalize
method existed, but IPython showed it to you.
You've seen the mechanics of working with the IPython Notebook. Now it's time to work through the tutorial.
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!