diff --git a/BasicPython/Sets IN python/Python_Set.ipynb b/BasicPython/Sets IN python/Python_Set.ipynb index 7ea6d08..b34c194 100644 --- a/BasicPython/Sets IN python/Python_Set.ipynb +++ b/BasicPython/Sets IN python/Python_Set.ipynb @@ -26,7 +26,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 39, "metadata": {}, "outputs": [ { @@ -49,7 +49,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 40, "metadata": {}, "outputs": [ { @@ -83,7 +83,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 41, "metadata": {}, "outputs": [ { @@ -117,7 +117,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 42, "metadata": {}, "outputs": [ { @@ -160,7 +160,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 43, "metadata": {}, "outputs": [ { @@ -197,7 +197,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 44, "metadata": {}, "outputs": [ { @@ -225,7 +225,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 45, "metadata": {}, "outputs": [ { @@ -257,7 +257,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 46, "metadata": {}, "outputs": [ { @@ -296,7 +296,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 47, "metadata": {}, "outputs": [ { @@ -333,7 +333,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 48, "metadata": {}, "outputs": [ { @@ -342,18 +342,8 @@ "text": [ "my_set --> {'A', 'B'}\n", "After pop --> {'B'}\n", - "After pop --> set()\n" - ] - }, - { - "ename": "KeyError", - "evalue": "'pop from an empty set'", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[1;32mIn[26], line 10\u001b[0m\n\u001b[0;32m 7\u001b[0m my_set\u001b[38;5;241m.\u001b[39mpop()\n\u001b[0;32m 8\u001b[0m \u001b[38;5;28mprint\u001b[39m (\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAfter pop -->\u001b[39m\u001b[38;5;124m\"\u001b[39m, my_set)\n\u001b[1;32m---> 10\u001b[0m \u001b[43mmy_set\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpop\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;66;03m# Error; Set is empty; Under flow\u001b[39;00m\n\u001b[0;32m 11\u001b[0m \u001b[38;5;28mprint\u001b[39m (\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAfter pop -->\u001b[39m\u001b[38;5;124m\"\u001b[39m, my_set)\n", - "\u001b[1;31mKeyError\u001b[0m: 'pop from an empty set'" + "After pop --> set()\n", + "Set is empty\n" ] } ], @@ -387,9 +377,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 49, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "my_set --> {'P', 'T', 'Q', 'R', 'S'}\n", + "Set after clear --> set()\n" + ] + } + ], "source": [ "my_set = set(['P', 'Q', 'R', 'S','T' ])\n", "print (\"my_set -->\", my_set)\n", @@ -407,17 +406,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 50, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Set after delete --> set()\n" + ] + } + ], "source": [ - "my_set = set([1,2,3,4,5 ])\n", - "print (\"my_set -->\", my_set)\n", - "\n", - "del my_set\n", - "print (\"Set after delete -->\", my_set) # Error\n", - " # Set is deleted and still want to print\n", - " # Exception should me handle\n" + "try:\n", + " print(\"Set after delete -->\", my_set)\n", + "except NameError:\n", + " print(\"Set is deleted and cannot be printed.\")\n" ] }, {