From 5a1836b857a7e8f761cf40d2654a27ce7671db04 Mon Sep 17 00:00:00 2001 From: Vasu Malhotra Date: Tue, 22 Oct 2019 14:50:19 +0530 Subject: [PATCH] Code commented and refreshed --- class2.ipynb | 157 ++++++++++++++++++++++++--------------------------- 1 file changed, 75 insertions(+), 82 deletions(-) diff --git a/class2.ipynb b/class2.ipynb index 0be32d0..cf294f5 100644 --- a/class2.ipynb +++ b/class2.ipynb @@ -42,7 +42,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -51,7 +51,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -68,7 +68,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -77,7 +77,7 @@ "'h'" ] }, - "execution_count": 13, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -88,7 +88,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -97,7 +97,7 @@ "'hel'" ] }, - "execution_count": 15, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -108,7 +108,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -117,7 +117,7 @@ "'hello'" ] }, - "execution_count": 18, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -128,7 +128,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -137,7 +137,7 @@ "5" ] }, - "execution_count": 17, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -148,7 +148,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -158,18 +158,18 @@ "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\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;34m'jello'\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'h'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;34m'jello'\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'h'\u001b[0m \u001b[0;31m# Strings are immutable in Python\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mTypeError\u001b[0m: 'str' object does not support item assignment" ] } ], "source": [ - "'jello'[0] = 'h'" + "'jello'[0] = 'h' # Strings are immutable in Python" ] }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -178,14 +178,14 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "hello 4434715624\n" + "hello 139900981603216\n" ] } ], @@ -195,23 +195,23 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ - "x = 'hello' + 'python'" + "x = 'hello' + 'python' # String concatenation using '+' operator" ] }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "hellopython 4435060656\n" + "hellopython 139900981567088\n" ] } ], @@ -221,14 +221,14 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "4396779584\n" + "93891300275360\n" ] } ], @@ -239,7 +239,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ @@ -248,14 +248,14 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "7 4396779648\n" + "7 93891300275424\n" ] } ], @@ -265,7 +265,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ @@ -274,7 +274,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ @@ -283,7 +283,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ @@ -292,14 +292,14 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "4396779584 4396779584 4396779584\n" + "93891300275360 93891300275360 93891300275360\n" ] } ], @@ -309,7 +309,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 21, "metadata": {}, "outputs": [ { @@ -318,7 +318,7 @@ "True" ] }, - "execution_count": 32, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -329,7 +329,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ @@ -338,7 +338,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ @@ -347,14 +347,14 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 24, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "4434727856 4434728016\n" + "139900981815888 139900981815376\n" ] } ], @@ -364,7 +364,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 25, "metadata": {}, "outputs": [ { @@ -373,7 +373,7 @@ "True" ] }, - "execution_count": 36, + "execution_count": 25, "metadata": {}, "output_type": "execute_result" } @@ -384,7 +384,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 26, "metadata": {}, "outputs": [ { @@ -393,18 +393,18 @@ "False" ] }, - "execution_count": 37, + "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "x is y" + "x is y # Only gives True if both points to the same object in memory" ] }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 27, "metadata": {}, "outputs": [], "source": [ @@ -413,7 +413,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 28, "metadata": {}, "outputs": [], "source": [ @@ -422,7 +422,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 29, "metadata": {}, "outputs": [ { @@ -431,7 +431,7 @@ "True" ] }, - "execution_count": 40, + "execution_count": 29, "metadata": {}, "output_type": "execute_result" } @@ -442,7 +442,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 30, "metadata": {}, "outputs": [ { @@ -451,18 +451,18 @@ "True" ] }, - "execution_count": 41, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "y is x" + "y is x # y and x points to the same 'int' object in memory" ] }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 31, "metadata": {}, "outputs": [ { @@ -474,13 +474,13 @@ } ], "source": [ - "if 10>4:\n", + "if 10 > 4:\n", " print('yes, it is.')" ] }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 32, "metadata": {}, "outputs": [ { @@ -497,7 +497,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 33, "metadata": {}, "outputs": [ { @@ -509,15 +509,15 @@ } ], "source": [ - "if 0.0:\n", + "if 0.0: # 0 evaluates to False\n", " print('if block')\n", " if 5<10:\n", " print('second if block')\n", - "elif '':\n", + "elif '': # Empty string evaluates to False\n", " print('child if of 1St if')\n", "elif False:\n", " print('second elif')\n", - "elif 'wow':\n", + "elif 'wow': # Evaluates to True\n", " print('third elif')\n", "else:\n", " print('else block')" @@ -525,7 +525,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 34, "metadata": {}, "outputs": [], "source": [ @@ -534,7 +534,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 35, "metadata": {}, "outputs": [ { @@ -551,7 +551,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 36, "metadata": {}, "outputs": [ { @@ -560,18 +560,18 @@ "0" ] }, - "execution_count": 48, + "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "10%2" + "10%2 # '%' is modulo operator" ] }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 37, "metadata": {}, "outputs": [], "source": [ @@ -580,7 +580,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 38, "metadata": {}, "outputs": [ { @@ -610,7 +610,7 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 39, "metadata": {}, "outputs": [ { @@ -633,7 +633,7 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 40, "metadata": {}, "outputs": [ { @@ -655,7 +655,7 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 41, "metadata": {}, "outputs": [ { @@ -677,7 +677,7 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 42, "metadata": {}, "outputs": [ { @@ -699,7 +699,7 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 43, "metadata": {}, "outputs": [ { @@ -720,14 +720,14 @@ }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 44, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Enter a number6\n" + "Enter a number\n" ] } ], @@ -737,14 +737,14 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 45, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "6\n" + "\n" ] } ], @@ -754,7 +754,7 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": 46, "metadata": {}, "outputs": [ { @@ -766,12 +766,12 @@ } ], "source": [ - "print(type(x))" + "print(type(x)) # input() always returns a string" ] }, { "cell_type": "code", - "execution_count": 68, + "execution_count": 47, "metadata": {}, "outputs": [ { @@ -793,13 +793,6 @@ " print('third')\n", " " ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -818,7 +811,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5rc1" + "version": "3.7.3" } }, "nbformat": 4,