{ "metadata": { "name": "basic_training" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "01_BasicTraining\n", "=============" ] }, { "cell_type": "code", "collapsed": false, "input": [ "print \"Hello World!\"" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Hello World!\n" ] } ], "prompt_number": 3 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Calculator ###" ] }, { "cell_type": "code", "collapsed": false, "input": [ "print 2 + 2" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "4\n" ] } ], "prompt_number": 4 }, { "cell_type": "code", "collapsed": false, "input": [ "2 + 2" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 5, "text": [ "4" ] } ], "prompt_number": 5 }, { "cell_type": "code", "collapsed": false, "input": [ "print 2.1 + 2" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "4.1\n" ] } ], "prompt_number": 6 }, { "cell_type": "code", "collapsed": false, "input": [ "2.1 + 2 == 4.0999999999999996" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 7, "text": [ "True" ] } ], "prompt_number": 7 }, { "cell_type": "code", "collapsed": false, "input": [ "(3.0*10.0 - 25.0)/5.0" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 8, "text": [ "1.0" ] } ], "prompt_number": 8 }, { "cell_type": "code", "collapsed": false, "input": [ "print 3.085e18*1e6 # this is a Megaparsec in units of cm!" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "3.085e+24\n" ] } ], "prompt_number": 9 }, { "cell_type": "code", "collapsed": false, "input": [ "t = 1.0 # declare a variable t (time)\n", "accel = 9.8 # acceleration in units of m/s^2\n", "# distance travelled in time t seconds is 1/2 a*t**2\n", "dist = 0.5*accel*t*t\n", "print dist # this is the distance in meters" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "4.9\n" ] } ], "prompt_number": 10 }, { "cell_type": "code", "collapsed": false, "input": [ "dist1 = accel*(t**2)/2\n", "print dist1" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "4.9\n" ] } ], "prompt_number": 11 }, { "cell_type": "code", "collapsed": false, "input": [ "dist2 = 0.5*accel*pow(t,2)\n", "print dist2" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "4.9\n" ] } ], "prompt_number": 12 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Some Mathy Operators" ] }, { "cell_type": "code", "collapsed": false, "input": [ "print 6 / 5 ; print 9 / 5 # integer division returns the floor" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "1\n", "1\n" ] } ], "prompt_number": 13 }, { "cell_type": "code", "collapsed": false, "input": [ "6 % 5 # mod operator" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 14, "text": [ "1" ] } ], "prompt_number": 14 }, { "cell_type": "code", "collapsed": false, "input": [ "1 << 2 ## shift: move the number 1 by two bits to the left\n", " ## that is make a new number 100 (base 2)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 15, "text": [ "4" ] } ], "prompt_number": 15 }, { "cell_type": "code", "collapsed": false, "input": [ "5 >> 1 ## shift: move the number 5 = 101 (base 2) one to\n", " ## to the right (10 = 2)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 16, "text": [ "2" ] } ], "prompt_number": 16 }, { "cell_type": "code", "collapsed": false, "input": [ "x = 2 ; y = 3 ## assign two variables on the same line!\n", "x | y ## bitwise OR" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 17, "text": [ "3" ] } ], "prompt_number": 17 }, { "cell_type": "code", "collapsed": false, "input": [ "x ^ y ## exclusive OR (10 ^ 11 = 01)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 18, "text": [ "1" ] } ], "prompt_number": 18 }, { "cell_type": "code", "collapsed": false, "input": [ "x & y ## bitwise AND" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 19, "text": [ "2" ] } ], "prompt_number": 19 }, { "cell_type": "code", "collapsed": false, "input": [ "x = x ^ y ; print x" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "1\n" ] } ], "prompt_number": 20 }, { "cell_type": "code", "collapsed": false, "input": [ "x += 3 ; print x" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "4\n" ] } ], "prompt_number": 21 }, { "cell_type": "code", "collapsed": false, "input": [ "x /= 2.0\n", "print x" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "2.0\n" ] } ], "prompt_number": 22 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Testing Relationships" ] }, { "cell_type": "code", "collapsed": false, "input": [ "dist1 = 4.9 ; dist = 4.9\n", "dist1 == dist" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 23, "text": [ "True" ] } ], "prompt_number": 23 }, { "cell_type": "code", "collapsed": false, "input": [ "dist < 10" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 24, "text": [ "True" ] } ], "prompt_number": 24 }, { "cell_type": "code", "collapsed": false, "input": [ "dist <= 4.9" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 25, "text": [ "True" ] } ], "prompt_number": 25 }, { "cell_type": "code", "collapsed": false, "input": [ "dist < (10 + 2j)" ], "language": "python", "metadata": {}, "outputs": [ { "ename": "TypeError", "evalue": "no ordering relation is defined for complex numbers", "output_type": "pyerr", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdist\u001b[0m \u001b[0;34m<\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;36m10\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m2j\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mTypeError\u001b[0m: no ordering relation is defined for complex numbers" ] } ], "prompt_number": 26 }, { "cell_type": "code", "collapsed": false, "input": [ "dist < -2.0" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "dist != 3.1415 # in the future you could use math.pi" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 27, "text": [ "True" ] } ], "prompt_number": 27 }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### More on Variables & Types ####\n", "##### None, numbers and truth #####" ] }, { "cell_type": "code", "collapsed": false, "input": [ "0 == False" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 28, "text": [ "True" ] } ], "prompt_number": 28 }, { "cell_type": "code", "collapsed": false, "input": [ "not False" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 29, "text": [ "True" ] } ], "prompt_number": 29 }, { "cell_type": "code", "collapsed": false, "input": [ "0.0 == False" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 30, "text": [ "True" ] } ], "prompt_number": 30 }, { "cell_type": "code", "collapsed": false, "input": [ "not (10.0 - 10.0)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 31, "text": [ "True" ] } ], "prompt_number": 31 }, { "cell_type": "code", "collapsed": false, "input": [ "not -1" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 32, "text": [ "False" ] } ], "prompt_number": 32 }, { "cell_type": "code", "collapsed": false, "input": [ "not 3.1415" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 33, "text": [ "False" ] } ], "prompt_number": 33 }, { "cell_type": "code", "collapsed": false, "input": [ "x = None # None is something special. Not true or false\n", "print None == False\n", "print None == True\n", "print None == None" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "False\n", "False\n", "True\n" ] } ], "prompt_number": 34 }, { "cell_type": "code", "collapsed": false, "input": [ "print False or True\n", "print False and True" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "True\n", "False\n" ] } ], "prompt_number": 35 }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### More on Variables & Types ####" ] }, { "cell_type": "code", "collapsed": false, "input": [ "print type(1)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "\n" ] } ], "prompt_number": 36 }, { "cell_type": "code", "collapsed": false, "input": [ "x = 2 ; print type(x)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "\n" ] } ], "prompt_number": 37 }, { "cell_type": "code", "collapsed": false, "input": [ "type(2) == type(1)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 38, "text": [ "True" ] } ], "prompt_number": 38 }, { "cell_type": "code", "collapsed": false, "input": [ "print type(True)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "\n" ] } ], "prompt_number": 39 }, { "cell_type": "code", "collapsed": false, "input": [ "print type(type(1))" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "\n" ] } ], "prompt_number": 40 }, { "cell_type": "code", "collapsed": false, "input": [ "print type(pow)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "\n" ] } ], "prompt_number": 41 }, { "cell_type": "markdown", "metadata": {}, "source": [ "we can test whether something is a certain type with `isinstance()`" ] }, { "cell_type": "code", "collapsed": false, "input": [ "print isinstance(1,int)\n", "print isinstance(\"spam\",str)\n", "print isinstance(1.212,int)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "True\n", "True\n", "False\n" ] } ], "prompt_number": 42 }, { "cell_type": "markdown", "metadata": {}, "source": [ "builtin-types: `int`, `bool`, `str`, `float`, `complex`, `long`...." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Strings ###" ] }, { "cell_type": "code", "collapsed": false, "input": [ "x = \"spam\" ; type(x)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 43, "text": [ "str" ] } ], "prompt_number": 43 }, { "cell_type": "code", "collapsed": false, "input": [ "print \"hello!\\n...my sire.\"" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "hello!\n", "...my sire.\n" ] } ], "prompt_number": 44 }, { "cell_type": "code", "collapsed": false, "input": [ "\"hello!\\n...my sire.\"" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 45, "text": [ "'hello!\\n...my sire.'" ] } ], "prompt_number": 45 }, { "cell_type": "code", "collapsed": false, "input": [ "\"wah?!\" == 'wah?!'" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 46, "text": [ "True" ] } ], "prompt_number": 46 }, { "cell_type": "code", "collapsed": false, "input": [ "print \"'wah?!' said the student\"" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "'wah?!' said the student\n" ] } ], "prompt_number": 47 }, { "cell_type": "code", "collapsed": false, "input": [ "print \"\\\"wah?!\\\" said the student\"" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "\"wah?!\" said the student\n" ] } ], "prompt_number": 48 }, { "cell_type": "markdown", "metadata": {}, "source": [ "backslashes (`\\`) start special (escape) characters:\n", "\n", " \\n = newline (\\r = return)\n", " \\t = tab\n", " \\a = bell\n", "\n", "string literals are defined with double quotes or quotes.\n", "the outermost quote type cannot be used inside the string (unless it's escaped with a backslash)" ] }, { "cell_type": "code", "collapsed": false, "input": [ "# raw strings don't escape characters\n", "print r'This is a raw string...newlines \\r\\n are ignored.'" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "This is a raw string...newlines \\r\\n are ignored.\n" ] } ], "prompt_number": 49 }, { "cell_type": "code", "collapsed": false, "input": [ "# Triple quotes are real useful for multiple line strings\n", "y = '''For score and seven minutes ago,\n", " you folks all learned some basic mathy stuff with Python\n", " and boy were you blown away!'''\n", "print y" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "For score and seven minutes ago,\n", " you folks all learned some basic mathy stuff with Python\n", " and boy were you blown away!\n" ] } ], "prompt_number": 50 }, { "cell_type": "markdown", "metadata": {}, "source": [ "* prepending `r` makes that string \"raw\"\n", "* triple quotes allow you to compose long strings\n", "* prepending `u` makes that string \"unicode\"\n", "\n", "http://docs.python.org/reference/lexical_analysis.html#string-literals" ] }, { "cell_type": "code", "collapsed": false, "input": [ "s = \"spam\" ; e = \"eggs\"\n", "print s + e" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "spameggs\n" ] } ], "prompt_number": 51 }, { "cell_type": "code", "collapsed": false, "input": [ "print s + \" and \" + e" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "spam and eggs\n" ] } ], "prompt_number": 52 }, { "cell_type": "code", "collapsed": false, "input": [ "print \"green \" + e + \" and\\n \" + s" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "green eggs and\n", " spam\n" ] } ], "prompt_number": 53 }, { "cell_type": "code", "collapsed": false, "input": [ "print s*3 + e" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "spamspamspameggs\n" ] } ], "prompt_number": 54 }, { "cell_type": "code", "collapsed": false, "input": [ "print \"*\"*50" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "**************************************************\n" ] } ], "prompt_number": 55 }, { "cell_type": "code", "collapsed": false, "input": [ "print \"spam\" is \"good\" ; print \"spam\" is \"spam\"" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "False\n", "True\n" ] } ], "prompt_number": 56 }, { "cell_type": "code", "collapsed": false, "input": [ "\"spam\" < \"zoo\"" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 57, "text": [ "True" ] } ], "prompt_number": 57 }, { "cell_type": "code", "collapsed": false, "input": [ "\"s\" < \"spam\"" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 58, "text": [ "True" ] } ], "prompt_number": 58 }, { "cell_type": "markdown", "metadata": {}, "source": [ "* you can concatenate strings with `+` sign\n", "* you can do multiple concatenations with the `*` sign\n", "* strings can be compared" ] }, { "cell_type": "code", "collapsed": false, "input": [ "print 'I want' + 3 + ' eggs and no ' + s" ], "language": "python", "metadata": {}, "outputs": [ { "ename": "TypeError", "evalue": "cannot concatenate 'str' and 'int' objects", "output_type": "pyerr", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mprint\u001b[0m \u001b[0;34m'I want'\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m3\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m' eggs and no '\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0ms\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mTypeError\u001b[0m: cannot concatenate 'str' and 'int' objects" ] } ], "prompt_number": 59 }, { "cell_type": "code", "collapsed": false, "input": [ "print 'I want ' + str(3) + ' eggs and no ' + s " ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "I want 3 eggs and no spam\n" ] } ], "prompt_number": 60 }, { "cell_type": "code", "collapsed": false, "input": [ "pi = 3.14159\n", "print 'I want ' + str(pi) + ' eggs and no ' + s" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "I want 3.14159 eggs and no spam\n" ] } ], "prompt_number": 61 }, { "cell_type": "code", "collapsed": false, "input": [ "print str(True) + \":\" + ' I want ' + str(pi) + ' eggs and no ' + s" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "True: I want 3.14159 eggs and no spam\n" ] } ], "prompt_number": 62 }, { "cell_type": "markdown", "metadata": {}, "source": [ "you must concatenate only strings, coercing (\"casting\") \n", "other variable types to `str`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can think of strings as arrays\n", "(although, unlike in C you never really need to deal with directly addressing character locations in memory)" ] }, { "cell_type": "code", "collapsed": false, "input": [ "s = 'spam'\n", "len(s)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 63, "text": [ "4" ] } ], "prompt_number": 63 }, { "cell_type": "code", "collapsed": false, "input": [ "len(\"eggs\\n\")\n", "len(\"\")" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 64, "text": [ "0" ] } ], "prompt_number": 64 }, { "cell_type": "code", "collapsed": false, "input": [ "print s[0]\n", "print s[-1]" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "s\n", "m\n" ] } ], "prompt_number": 65 }, { "cell_type": "markdown", "metadata": {}, "source": [ "* `len()` gives us the length of an array\n", "* strings are zero indexed\n", "* can also count backwards" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Flow is done within blocks (where indentation matters) ###" ] }, { "cell_type": "code", "collapsed": false, "input": [ "x = 1\n", "if x > 0:\n", " print \"yo\"\n", "else:\n", " print \"dude\"" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "yo\n" ] } ], "prompt_number": 66 }, { "cell_type": "code", "collapsed": false, "input": [ "x = 1\n", "if x > 0:\n", " print \"yo\"\n", "else:\n", " print \"dude\"" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "yo\n" ] } ], "prompt_number": 67 }, { "cell_type": "markdown", "metadata": {}, "source": [ "One liners" ] }, { "cell_type": "code", "collapsed": false, "input": [ "print \"yo\" if x > 0 else \"dude\"" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "yo\n" ] } ], "prompt_number": 68 }, { "cell_type": "markdown", "metadata": {}, "source": [ "case statements can be constructed with \n", "just a bunch of `if`, `elif`,...`else`" ] }, { "cell_type": "code", "collapsed": false, "input": [ "if x < 1:\n", " print \"t\"\n", "elif x > 100:\n", " print \"yo\"\n", "else:\n", " print \"dude\"" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "dude\n" ] } ], "prompt_number": 69 }, { "cell_type": "markdown", "metadata": {}, "source": [ "ordering matters. The first block of `True` in an if/elif gets executed then everything else does not.\n", "\n", "#### blocks cannot be empty ####" ] }, { "cell_type": "code", "collapsed": false, "input": [ "x = \"fried goldfish\"\n", "if x == \"spam for dinner\":\n", " print \"I will destroy the universe\"\n", "else:\n", " # I'm fine with that. I'll do nothing" ], "language": "python", "metadata": {}, "outputs": [ { "ename": "IndentationError", "evalue": "expected an indented block (, line 5)", "output_type": "pyerr", "traceback": [ "\u001b[0;31mIndentationError\u001b[0m\u001b[0;31m:\u001b[0m expected an indented block\n" ] } ], "prompt_number": 70 }, { "cell_type": "code", "collapsed": true, "input": [ "x = \"fried goldfish\"\n", "if x == \"spam for dinner\":\n", " print \"I will destroy the universe\"\n", "else:\n", " # I'm fine with that. I'll do nothing\n", " pass" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 71 }, { "cell_type": "markdown", "metadata": {}, "source": [ "`pass` is a \"do nothing\"/NOP statement" ] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 77 } ], "metadata": {} } ] }