|
2338 | 2338 | "# Bad indentation!\n", |
2339 | 2339 | "if statement1:\n", |
2340 | 2340 | " if statement2:\n", |
2341 | | - " print(\"both statement1 and statement2 are True\") # this line is not properly indented" |
| 2341 | + " print(\"both statement1 and statement2 are True\") # this line is not properly indented" |
2342 | 2342 | ], |
2343 | 2343 | "language": "python", |
2344 | 2344 | "metadata": {}, |
2345 | 2345 | "outputs": [ |
2346 | 2346 | { |
2347 | | - "output_type": "stream", |
2348 | | - "stream": "stdout", |
2349 | | - "text": [ |
2350 | | - "both statement1 and statement2 are True\n" |
| 2347 | + "ename": "IndentationError", |
| 2348 | + "evalue": "expected an indented block (<ipython-input-88-78979cdecf37>, line 4)", |
| 2349 | + "output_type": "pyerr", |
| 2350 | + "traceback": [ |
| 2351 | + "\u001b[1;36m File \u001b[1;32m\"<ipython-input-88-78979cdecf37>\"\u001b[1;36m, line \u001b[1;32m4\u001b[0m\n\u001b[1;33m print(\"both statement1 and statement2 are True\") # this line is not properly indented\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m expected an indented block\n" |
2351 | 2352 | ] |
2352 | 2353 | } |
2353 | 2354 | ], |
|
2653 | 2654 | "source": [ |
2654 | 2655 | "## Functions\n", |
2655 | 2656 | "\n", |
2656 | | - "A function in Python is defined using the keyword `def`, followed by a function name, a signature within parenthises `()`, and a colon `:`. The following code, with one additional level of indentation, is the function body." |
| 2657 | + "A function in Python is defined using the keyword `def`, followed by a function name, a signature within parentheses `()`, and a colon `:`. The following code, with one additional level of indentation, is the function body." |
2657 | 2658 | ] |
2658 | 2659 | }, |
2659 | 2660 | { |
|
3017 | 3018 | "cell_type": "markdown", |
3018 | 3019 | "metadata": {}, |
3019 | 3020 | "source": [ |
3020 | | - "This technique is useful for exmample when we want to pass a simple function as an argument to another function, like this:" |
| 3021 | + "This technique is useful for example when we want to pass a simple function as an argument to another function, like this:" |
3021 | 3022 | ] |
3022 | 3023 | }, |
3023 | 3024 | { |
|
3072 | 3073 | "\n", |
3073 | 3074 | "In Python a class can contain *attributes* (variables) and *methods* (functions).\n", |
3074 | 3075 | "\n", |
3075 | | - "In python a class is defined almost like a function, but using the `class` keyword, and the class definition usually contains a number of class method definitions (a function in a class).\n", |
| 3076 | + "A class is defined almost like a function, but using the `class` keyword, and the class definition usually contains a number of class method definitions (a function in a class).\n", |
3076 | 3077 | "\n", |
3077 | | - "* Each class method should have an argurment `self` as it first argument. This object is a self-reference.\n", |
| 3078 | + "* Each class method should have an argument `self` as it first argument. This object is a self-reference.\n", |
3078 | 3079 | "\n", |
3079 | 3080 | "* Some class method names have special meaning, for example:\n", |
3080 | 3081 | "\n", |
3081 | | - " * `__init__`: The name of the method that is invoked when the object is first created.\n", |
3082 | | - " * `__str__` : A method that is invoked when a simple string representation of the class is needed, as for example when printed.\n", |
3083 | | - " * There are many more, see http://docs.python.org/2/reference/datamodel.html#special-method-names" |
| 3082 | + " * `__init__`: The name of the method that is invoked when the object is first created.\n", |
| 3083 | + " * `__str__` : A method that is invoked when a simple string representation of the class is needed, as for example when printed.\n", |
| 3084 | + " * There are many more, see http://docs.python.org/2/reference/datamodel.html#special-method-names" |
3084 | 3085 | ] |
3085 | 3086 | }, |
3086 | 3087 | { |
|
3127 | 3128 | "input": [ |
3128 | 3129 | "p1 = Point(0, 0) # this will invoke the __init__ method in the Point class\n", |
3129 | 3130 | "\n", |
3130 | | - "print(p1) # this will invode the __str__ method" |
| 3131 | + "print(p1) # this will invoke the __str__ method" |
3131 | 3132 | ], |
3132 | 3133 | "language": "python", |
3133 | 3134 | "metadata": {}, |
|
3419 | 3420 | "source": [ |
3420 | 3421 | "## Exceptions\n", |
3421 | 3422 | "\n", |
3422 | | - "In Python errors are managed with a special language construct called \"Exceptions\". When errors occur exceptions can be raised, which interrupts the normal program flow and fallback to somewhere else in the code where the closest try-except statements is defined.\n" |
| 3423 | + "In Python errors are managed with a special language construct called \"Exceptions\". When errors occur exceptions can be raised, which interrupts the normal program flow and fallback to somewhere else in the code where the closest try-except statement is defined.\n" |
3423 | 3424 | ] |
3424 | 3425 | }, |
3425 | 3426 | { |
|
0 commit comments