From 91674607120c2fef1f061ca1a73dfb592e662181 Mon Sep 17 00:00:00 2001 From: Arti Kumari Date: Thu, 10 Oct 2019 17:16:26 -0700 Subject: [PATCH] Edited and added --- .ipynb_checkpoints/class2-checkpoint.ipynb | 827 +++++++++++++++++++++ class2.ipynb | 419 +++++++++-- 2 files changed, 1192 insertions(+), 54 deletions(-) create mode 100644 .ipynb_checkpoints/class2-checkpoint.ipynb diff --git a/.ipynb_checkpoints/class2-checkpoint.ipynb b/.ipynb_checkpoints/class2-checkpoint.ipynb new file mode 100644 index 0000000..3529373 --- /dev/null +++ b/.ipynb_checkpoints/class2-checkpoint.ipynb @@ -0,0 +1,827 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "\"It's a string\"" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#\n", + "\"It's a string\"" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'It \"wow\" a string'" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'It \"wow\" a string'" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "t = 'hello this is long string ''python wow this is string'" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hello this is long string python wow this is string\n" + ] + } + ], + "source": [ + "print(t)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'h'" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'hello'[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'hel'" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'hello'[0:3]" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'hello'" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'hello'[0:2] + 'hello'[2:len('hello')]" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len('hello')" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "'str' object does not support item assignment", + "output_type": "error", + "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;31mTypeError\u001b[0m: 'str' object does not support item assignment" + ] + } + ], + "source": [ + "'jello'[0] = 'h'" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [], + "source": [ + "x = 'hello'" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hello 4434715624\n" + ] + } + ], + "source": [ + "print(x , id(x))" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [], + "source": [ + "x = 'hello' + 'python'" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hellopython 4435060656\n" + ] + } + ], + "source": [ + "print(x, id(x))" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4396779584\n" + ] + } + ], + "source": [ + "x = 5\n", + "print(id(5))" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [], + "source": [ + "x = x + 2" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "7 4396779648\n" + ] + } + ], + "source": [ + "print(x, id(x))" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [], + "source": [ + "x = 5" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "y = 5" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [], + "source": [ + "z = 5" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4396779584 4396779584 4396779584\n" + ] + } + ], + "source": [ + "print(id(x) , id(y) , id(z))" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x == y" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [], + "source": [ + "x = 123456789" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [], + "source": [ + "y = 123456789" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4434727856 4434728016\n" + ] + } + ], + "source": [ + "print(id(x) , id(y))" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x == y" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x is y" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [], + "source": [ + "x = 5" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [], + "source": [ + "y = x" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "y == x" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "y is x" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "yes, it is.\n" + ] + } + ], + "source": [ + "if 10>4:\n", + " print('yes, it is.')" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5\n" + ] + } + ], + "source": [ + " print(5)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "third elif\n" + ] + } + ], + "source": [ + "if 0.0:\n", + " print('if block')\n", + " if 5<10:\n", + " print('second if block')\n", + "elif '':\n", + " print('child if of 1St if')\n", + "elif False:\n", + " print('second elif')\n", + "elif 'wow':\n", + " print('third elif')\n", + "else:\n", + " print('else block')" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [], + "source": [ + "x = 5 if 20<10 else 'hello'" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hello\n" + ] + } + ], + "source": [ + "print(x)" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "10%2" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [], + "source": [ + "y = 10" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10\n", + "11\n", + "12\n", + "13\n", + "14\n", + "15\n", + "16\n", + "17\n", + "18\n", + "19\n", + "outside of loop\n" + ] + } + ], + "source": [ + "while y < 20:\n", + " print(y)\n", + " y = y+1\n", + "print('outside of loop')" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "else of while\n", + "this is outside loop\n" + ] + } + ], + "source": [ + "while False:\n", + " print('while is true')\n", + " break\n", + "else:\n", + " print('else of while')\n", + "print('this is outside loop')" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "h\n", + "e\n", + "l\n", + "l\n", + "o\n" + ] + } + ], + "source": [ + "for i in 'hello':\n", + " print(i)" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "1\n", + "2\n", + "3\n", + "4\n" + ] + } + ], + "source": [ + "for i in range(5):\n", + " print(i)" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5\n", + "6\n", + "7\n", + "8\n", + "9\n" + ] + } + ], + "source": [ + "for i in range(5 , 10):\n", + " print(i)" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n", + "4\n", + "6\n", + "8\n" + ] + } + ], + "source": [ + "for i in range(2, 10, 2):\n", + " print(i)" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter a number6\n" + ] + } + ], + "source": [ + "x = input('Enter a number')" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "6\n" + ] + } + ], + "source": [ + "print(x)" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "print(type(x))" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "first if\n", + "second if\n", + "third\n" + ] + } + ], + "source": [ + "if True:\n", + " print('first if')\n", + " if True:\n", + " print('second if')\n", + " if True:\n", + " print('third')\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/class2.ipynb b/class2.ipynb index 0be32d0..a250062 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,18 +77,19 @@ "'h'" ] }, - "execution_count": 13, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ + "#It will return element at 0 index\n", "'hello'[0]" ] }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -97,18 +98,20 @@ "'hel'" ] }, - "execution_count": 15, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ + "#It will return the element start from 0 till (3-1). It means it will return element from index 0 to 2\n", + "#hence It will return hel\n", "'hello'[0:3]" ] }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -117,18 +120,20 @@ "'hello'" ] }, - "execution_count": 18, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ + "# '+' is also used concatenation of string. 'hello'[0:2] will return 'he' and it will concatenate with 'hello'[2:5] len('hello') will return the length of the 'hello' which is 5.\n", + "#'hello'[2:5] will return elements from index 2 to (5-1) means 2 to 4 so it will return 'llo' and 'he'+'llo' will make 'hello'.\n", "'hello'[0:2] + 'hello'[2:len('hello')]" ] }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -137,7 +142,7 @@ "5" ] }, - "execution_count": 17, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -152,24 +157,22 @@ "metadata": {}, "outputs": [ { - "ename": "TypeError", - "evalue": "'str' object does not support item assignment", + "ename": "SyntaxError", + "evalue": "can't assign to literal (, line 3)", "output_type": "error", "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;31mTypeError\u001b[0m: 'str' object does not support item assignment" + "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m3\u001b[0m\n\u001b[1;33m 'jello'= 'h'\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m can't assign to literal\n" ] } ], "source": [ + "#String does not support item assignment\n", "'jello'[0] = 'h'" ] }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ @@ -178,24 +181,33 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 34, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "hello 4434715624\n" + "id of x 2323770676480\n", + "id of a 2323770676480\n", + "id of b 2323771261360\n" ] } ], "source": [ - "print(x , id(x))" + "#Python id() function returns the “identity” of the object. The identity of an object is an integer, which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value.\n", + "print('id of x' , id(x))\n", + "a='hello'\n", + "b='hello Arti'\n", + "print('id of a',id(a))\n", + "print('id of b',id(b))\n", + "\n", + "#a and x have same value so the have same id but b have different value so it have differnet id" ] }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 35, "metadata": {}, "outputs": [], "source": [ @@ -204,31 +216,32 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 37, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "hellopython 4435060656\n" + "hellopython 2323771262384\n" ] } ], "source": [ + "#Variable value has been changed so its id will change from previous id\n", "print(x, id(x))" ] }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 38, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "4396779584\n" + "140729982686144\n" ] } ], @@ -239,7 +252,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 39, "metadata": {}, "outputs": [], "source": [ @@ -248,18 +261,19 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 40, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "7 4396779648\n" + "7 140729982686208\n" ] } ], "source": [ + "#value of a variable has been change so it id value will change\n", "print(x, id(x))" ] }, @@ -359,6 +373,7 @@ } ], "source": [ + "#Two variable having same value will have same id value\n", "print(id(x) , id(y))" ] }, @@ -509,17 +524,18 @@ } ], "source": [ - "if 0.0:\n", + "#if statement runs only when its if condition return non zero value\n", + "if 0.0: # here 0.0 which is returning 0 so it will not execute its if body\n", " print('if block')\n", " if 5<10:\n", " print('second if block')\n", - "elif '':\n", + "elif '': #here '' it is returning null so it will not execute its body\n", " print('child if of 1St if')\n", - "elif False:\n", + "elif False: # False return 0 so its body will not exexute\n", " print('second elif')\n", - "elif 'wow':\n", + "elif 'wow': # 'wow' is a string and it will non zero value and hence its body will exexute\n", " print('third elif')\n", - "else:\n", + "else: # Third elif has been executed so compiler will not execute this\n", " print('else block')" ] }, @@ -551,22 +567,23 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 50, "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "0" - ] - }, - "execution_count": 48, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "5.0\n" + ] } ], "source": [ - "10%2" + "# % operator will return remainder\n", + "print(10%2)\n", + "#/ opeator will return quotient\n", + "print(10/2)" ] }, { @@ -578,6 +595,36 @@ "y = 10" ] }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "1\n", + "2\n", + "3\n", + "4\n", + "5\n", + "6\n", + "7\n", + "8\n", + "9\n", + "outside of loop\n" + ] + } + ], + "source": [ + "# for loop\n", + "for i in range(10):\n", + " print(i)\n", + "print('outside of loop') " + ] + }, { "cell_type": "code", "execution_count": 54, @@ -602,15 +649,16 @@ } ], "source": [ + "#Body of loop will execute till the conditoion statement of while is true(y<20)\n", "while y < 20:\n", - " print(y)\n", - " y = y+1\n", + " print(y)\n", + " y = y+1\n", "print('outside of loop')" ] }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 56, "metadata": {}, "outputs": [ { @@ -618,17 +666,27 @@ "output_type": "stream", "text": [ "else of while\n", + "this is outside loop\n", + "while is true\n", "this is outside loop\n" ] } ], "source": [ + "#if condition of while is not true then else body will execute otherwise not\n", "while False:\n", " print('while is true')\n", " break\n", "else:\n", " print('else of while')\n", - "print('this is outside loop')" + "print('this is outside loop')\n", + "\n", + "while True:\n", + " print('while is true')\n", + " break\n", + "else:\n", + " print('else of while')\n", + "print('this is outside loop')\n" ] }, { @@ -699,7 +757,7 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 60, "metadata": {}, "outputs": [ { @@ -709,29 +767,39 @@ "2\n", "4\n", "6\n", - "8\n" + "8\n", + "0\n", + "3\n", + "6\n", + "9\n" ] } ], "source": [ + "# i will increment in multiple of 2\n", "for i in range(2, 10, 2):\n", + " print(i)\n", + " \n", + "# i will increment in multiple of 3\n", + "for i in range(0, 12, 3):\n", " print(i)" ] }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 61, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Enter a number6\n" + "Enter a number3\n" ] } ], "source": [ + "#input is used to input the data\n", "x = input('Enter a number')" ] }, @@ -796,10 +864,253 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 62, + "metadata": {}, + "outputs": [], + "source": [ + "#converting base 2 to base 10\n", + "# initializing string \n", + "s = \"10010\"" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "After converting to integer base 2 : 18\n" + ] + } + ], + "source": [ + "# printing string converting to int base 2 \n", + "c = int(s,2) # c = 2*1+2^4\n", + "print (\"After converting to integer base 2 : \", end=\"\") \n", + "print (c)" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "After converting to float : 10010.0\n" + ] + } + ], + "source": [ + "# printing string converting to float \n", + "e = float(s) \n", + "print (\"After converting to float : \", end=\"\") \n", + "print (e) " + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "metadata": {}, + "outputs": [], + "source": [ + "s = '4'" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "After converting 56 to hexadecimal string : 0x38\n" + ] + } + ], + "source": [ + "# printing integer converting to hexadecimal string \n", + "c = hex(56) \n", + "print (\"After converting 56 to hexadecimal string : \",end=\"\") \n", + "print (c)" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "After converting 56 to octal string : 0o70\n" + ] + } + ], + "source": [ + "# printing integer converting to octal string \n", + "c = oct(56) \n", + "print (\"After converting 56 to octal string : \",end=\"\") \n", + "print (c) " + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": {}, + "outputs": [], + "source": [ + "s = 'Hacktober'" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "After converting string to tuple : ('H', 'a', 'c', 'k', 't', 'o', 'b', 'e', 'r')\n" + ] + } + ], + "source": [ + "# printing string converting to tuple \n", + "c = tuple(s) \n", + "print (\"After converting string to tuple : \",end=\"\") \n", + "print (c) " + ] + }, + { + "cell_type": "code", + "execution_count": 72, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "After converting string to set : {'c', 'a', 'e', 't', 'o', 'k', 'r', 'b', 'H'}\n" + ] + } + ], + "source": [ + "# printing string converting to set \n", + "c = set(s) \n", + "print (\"After converting string to set : \",end=\"\") \n", + "print (c) " + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "After converting string to list : ['H', 'a', 'c', 'k', 't', 'o', 'b', 'e', 'r']\n" + ] + } + ], + "source": [ + "# printing string converting to list \n", + "c = list(s) \n", + "print (\"After converting string to list : \",end=\"\") \n", + "print (c) " + ] + }, + { + "cell_type": "code", + "execution_count": 74, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "# initializing integers \n", + "a = 1\n", + "b = 2" + ] + }, + { + "cell_type": "code", + "execution_count": 75, + "metadata": {}, + "outputs": [], + "source": [ + "# initializing tuple \n", + "tup = (('a', 1) ,('f', 2), ('g', 3)) " + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "After converting integer to complex number : (1+2j)\n" + ] + } + ], + "source": [ + "# printing integer converting to complex number \n", + "c = complex(1,2) \n", + "print (\"After converting integer to complex number : \",end=\"\") \n", + "print (c) " + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "After converting integer to string : 1\n" + ] + } + ], + "source": [ + "# printing integer converting to string \n", + "c = str(a) \n", + "print (\"After converting integer to string : \",end=\"\") \n", + "print (c)" + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "After converting tuple to dictionary : {'a': 1, 'f': 2, 'g': 3}\n" + ] + } + ], + "source": [ + "# printing tuple converting to expression dictionary \n", + "c = dict(tup) \n", + "print (\"After converting tuple to dictionary : \",end=\"\") \n", + "print (c) " + ] } ], "metadata": { @@ -818,7 +1129,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5rc1" + "version": "3.7.3" } }, "nbformat": 4,