diff --git a/lecture_notebooks/L02 Variables and Expressions.ipynb b/lecture_notebooks/L02 Variables and Expressions.ipynb index f13908e..0754515 100644 --- a/lecture_notebooks/L02 Variables and Expressions.ipynb +++ b/lecture_notebooks/L02 Variables and Expressions.ipynb @@ -569,6 +569,32 @@ " print(\"boo\")" ] }, + { + "cell_type": "code", + "execution_count": 5, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "invalid syntax (450256079.py, line 5)", + "output_type": "error", + "traceback": [ + "\u001B[0;36m Cell \u001B[0;32mIn[5], line 5\u001B[0;36m\u001B[0m\n\u001B[0;31m print(x-=1)\u001B[0m\n\u001B[0m ^\u001B[0m\n\u001B[0;31mSyntaxError\u001B[0m\u001B[0;31m:\u001B[0m invalid syntax\n" + ] + } + ], + "source": [ + "# However, assignment statements, such as x -= y will not print\n", + "\n", + "# This is because assignment statements don't return a value for python to print\n", + "\n", + "# In this way we can differentiate from expressions\n", + "\n", + "print(x-=1)" + ], + "metadata": { + "collapsed": false + } + }, { "cell_type": "markdown", "metadata": { @@ -747,7 +773,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 12, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -773,24 +799,21 @@ { "data": { "text/plain": [ - "3.5" + "2" ] }, - "execution_count": 1, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "x = 7\n", - "y = 2\n", - "\n", "x / y # What's the value of this one ?" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 17, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -816,11 +839,13 @@ { "data": { "text/plain": [ - "3" + "2" ] }, - "execution_count": 2, - "metadata": {}, + "execution_count": 17, + "metadata": { + "tags": [] + }, "output_type": "execute_result" } ], @@ -831,9 +856,6 @@ { "cell_type": "markdown", "metadata": { - "pycharm": { - "name": "#%% md\n" - }, "slideshow": { "slide_type": "fragment" } @@ -1065,7 +1087,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 15, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -1092,10 +1114,10 @@ { "data": { "text/plain": [ - "'Thisiscontrived'" + "('This', 'is', 'contrived')" ] }, - "execution_count": 3, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -2781,9 +2803,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.15" + "version": "3.9.9" } }, "nbformat": 4, "nbformat_minor": 1 -} \ No newline at end of file +} diff --git a/lecture_notebooks/L03 More Types.ipynb b/lecture_notebooks/L03 More Types.ipynb index d9472b3..f0dd832 100644 --- a/lecture_notebooks/L03 More Types.ipynb +++ b/lecture_notebooks/L03 More Types.ipynb @@ -321,7 +321,7 @@ "evalue": "ignored", "output_type": "error", "traceback": [ - "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m type('This is a string containing a 'single quoted substring'')\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" + "\u001B[0;36m File \u001B[0;32m\"\"\u001B[0;36m, line \u001B[0;32m1\u001B[0m\n\u001B[0;31m type('This is a string containing a 'single quoted substring'')\u001B[0m\n\u001B[0m ^\u001B[0m\n\u001B[0;31mSyntaxError\u001B[0m\u001B[0;31m:\u001B[0m invalid syntax\n" ] } ], @@ -404,7 +404,7 @@ "evalue": "ignored", "output_type": "error", "traceback": [ - "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m type('This is an\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m EOL while scanning string literal\n" + "\u001B[0;36m File \u001B[0;32m\"\"\u001B[0;36m, line \u001B[0;32m1\u001B[0m\n\u001B[0;31m type('This is an\u001B[0m\n\u001B[0m ^\u001B[0m\n\u001B[0;31mSyntaxError\u001B[0m\u001B[0;31m:\u001B[0m EOL while scanning string literal\n" ] } ], @@ -976,9 +976,6 @@ { "cell_type": "markdown", "metadata": { - "pycharm": { - "name": "#%% md\n" - }, "slideshow": { "slide_type": "slide" } @@ -1026,18 +1023,15 @@ ] }, { - "cell_type": "markdown", - "metadata": { - "pycharm": { - "name": "#%%\n" - }, - "slideshow": { - "slide_type": "fragment" - } - }, + "cell_type": "code", + "execution_count": null, + "outputs": [], "source": [ "F-strings were introduced in Python 3.6. They provide a convenient alternative to the format method (see below)" - ] + ], + "metadata": { + "collapsed": false + } }, { "cell_type": "code", @@ -1521,15 +1515,15 @@ "evalue": "ignored", "output_type": "error", "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mValueError\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[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"foo\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mValueError\u001b[0m: invalid literal for int() with base 10: 'foo'" + "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", + "\u001B[0;31mValueError\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[0mint\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m\"foo\"\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m", + "\u001B[0;31mValueError\u001B[0m: invalid literal for int() with base 10: 'foo'" ] } ], "source": [ - "# Of course, this doesn't work because int() doesn't how\n", + "# Of course, this doesn't work because int() doesn't know how\n", "# to interpret 'foo'\n", "int(\"foo\")" ] @@ -1850,7 +1844,8 @@ } ], "source": [ - "type(x + 0.0) # Python will generally automatically switch into floating point to avoid losing the decimal" + "type(x + 0.0) # Python will generally automatically switch\n", + "# into floating point to avoid losing the decimal" ] }, {