├── README.md └── datatypes.ipynb /README.md: -------------------------------------------------------------------------------- 1 | # datatypes 2 | for formal use 3 | -------------------------------------------------------------------------------- /datatypes.ipynb: -------------------------------------------------------------------------------- 1 | {"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.10","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"1.>>> name = input('What is your name?\\n') # \\n ---> newline ---> It causes a line break\n >>> What is your name?\n Ram\n >>> print(name)\n Ram \n \n # ---> comment in python","metadata":{}},{"cell_type":"code","source":"val = input(\"Enter your value: \")\nprint(val)","metadata":{"execution":{"iopub.status.busy":"2023-07-04T15:08:24.261344Z","iopub.execute_input":"2023-07-04T15:08:24.261853Z","iopub.status.idle":"2023-07-04T15:08:31.722717Z","shell.execute_reply.started":"2023-07-04T15:08:24.261817Z","shell.execute_reply":"2023-07-04T15:08:31.720690Z"},"trusted":true},"execution_count":11,"outputs":[{"output_type":"stream","name":"stdin","text":"Enter your value: 23\n"},{"name":"stdout","text":"23\n","output_type":"stream"}]},{"cell_type":"code","source":"\nname = input('What is your name?\\n') # \\n ---> newline ---> It causes a line break\nprint(name)","metadata":{"execution":{"iopub.status.busy":"2023-07-04T15:08:31.725217Z","iopub.execute_input":"2023-07-04T15:08:31.725637Z","iopub.status.idle":"2023-07-04T15:08:42.553320Z","shell.execute_reply.started":"2023-07-04T15:08:31.725606Z","shell.execute_reply":"2023-07-04T15:08:42.551915Z"},"trusted":true},"execution_count":12,"outputs":[{"output_type":"stream","name":"stdin","text":"What is your name?\n microsoft\n"},{"name":"stdout","text":"microsoft\n","output_type":"stream"}]},{"cell_type":"code","source":"\n# Program to check input\n# type in Python\n \nnum = input (\"Enter number :\")\nprint(num)\nname1 = input(\"Enter name : \")\nprint(name1)\n \n# Printing type of input value\nprint (\"type of number\", type(num))\nprint (\"type of name\", type(name1))","metadata":{"execution":{"iopub.status.busy":"2023-07-04T15:08:42.555558Z","iopub.execute_input":"2023-07-04T15:08:42.555978Z","iopub.status.idle":"2023-07-04T15:08:54.841983Z","shell.execute_reply.started":"2023-07-04T15:08:42.555925Z","shell.execute_reply":"2023-07-04T15:08:54.841108Z"},"trusted":true},"execution_count":13,"outputs":[{"output_type":"stream","name":"stdin","text":"Enter number : 9\n"},{"name":"stdout","text":"9\n","output_type":"stream"},{"output_type":"stream","name":"stdin","text":"Enter name : microgoogle\n"},{"name":"stdout","text":"microgoogle\ntype of number \ntype of name \n","output_type":"stream"}]},{"cell_type":"code","source":"\nnum = int(input(\"Enter a number: \"))\nprint(num, \" \", type(num))\n \n \nfloatNum = float(input(\"Enter a decimal number: \"))\nprint(floatNum, \" \", type(floatNum))","metadata":{"execution":{"iopub.status.busy":"2023-07-04T15:08:54.844217Z","iopub.execute_input":"2023-07-04T15:08:54.845004Z","iopub.status.idle":"2023-07-04T15:09:04.761093Z","shell.execute_reply.started":"2023-07-04T15:08:54.844971Z","shell.execute_reply":"2023-07-04T15:09:04.759770Z"},"trusted":true},"execution_count":14,"outputs":[{"output_type":"stream","name":"stdin","text":"Enter a number: 159\n"},{"name":"stdout","text":"159 \n","output_type":"stream"},{"output_type":"stream","name":"stdin","text":"Enter a decimal number: 45\n"},{"name":"stdout","text":"45.0 \n","output_type":"stream"}]},{"cell_type":"markdown","source":"# Python List using [].","metadata":{}},{"cell_type":"markdown","source":"\nVar = [\"Geeks\", \"for\", \"Geeks\"]\nprint(Var)","metadata":{}},{"cell_type":"code","source":"\n# Python program to demonstrate\n# Creation of List\n \n# Creating a List\nList = []\nprint(\"Blank List: \")\nprint(List)\n \n# Creating a List of numbers\nList = [10, 20, 14]\nprint(\"\\nList of numbers: \")\nprint(List)\n \n# Creating a List of strings and accessing\n# using index\nList = [\"Geeks\", \"For\", \"Geeks\"]\nprint(\"\\nList Items: \")\nprint(List[0])\nprint(List[2])","metadata":{"execution":{"iopub.status.busy":"2023-07-04T15:09:04.762652Z","iopub.execute_input":"2023-07-04T15:09:04.763021Z","iopub.status.idle":"2023-07-04T15:09:04.772780Z","shell.execute_reply.started":"2023-07-04T15:09:04.762989Z","shell.execute_reply":"2023-07-04T15:09:04.771016Z"},"trusted":true},"execution_count":15,"outputs":[{"name":"stdout","text":"Blank List: \n[]\n\nList of numbers: \n[10, 20, 14]\n\nList Items: \nGeeks\nGeeks\n","output_type":"stream"}]},{"cell_type":"code","source":"# Creating a List with\n# the use of Numbers\n# (Having duplicate values)\nList = [1, 2, 4, 4, 3, 3, 3, 6, 5]\nprint(\"\\nList with the use of Numbers: \")\nprint(List)\n\n# Creating a List with\n# mixed type of values\n# (Having numbers and strings)\nList = [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']\nprint(\"\\nList with the use of Mixed Values: \")\nprint(List)","metadata":{"execution":{"iopub.status.busy":"2023-07-04T15:09:04.775080Z","iopub.execute_input":"2023-07-04T15:09:04.775582Z","iopub.status.idle":"2023-07-04T15:09:04.790751Z","shell.execute_reply.started":"2023-07-04T15:09:04.775548Z","shell.execute_reply":"2023-07-04T15:09:04.789187Z"},"trusted":true},"execution_count":16,"outputs":[{"name":"stdout","text":"\nList with the use of Numbers: \n[1, 2, 4, 4, 3, 3, 3, 6, 5]\n\nList with the use of Mixed Values: \n[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']\n","output_type":"stream"}]},{"cell_type":"code","source":"# Python program to demonstrate\n# accessing of element from list\n\n# Creating a List with\n# the use of multiple values\nList = [\"Geeks\", \"For\", \"Geeks\"]\n\n# accessing a element from the\n# list using index number\nprint(\"Accessing a element from the list\")\nprint(List[0])\nprint(List[2])\n","metadata":{"execution":{"iopub.status.busy":"2023-07-04T15:09:04.792517Z","iopub.execute_input":"2023-07-04T15:09:04.792871Z","iopub.status.idle":"2023-07-04T15:09:04.810882Z","shell.execute_reply.started":"2023-07-04T15:09:04.792844Z","shell.execute_reply":"2023-07-04T15:09:04.809488Z"},"trusted":true},"execution_count":17,"outputs":[{"name":"stdout","text":"Accessing a element from the list\nGeeks\nGeeks\n","output_type":"stream"}]},{"cell_type":"code","source":"# Creating a Multi-Dimensional List\n# (By Nesting a list inside a List)\nList = [['Geeks', 'For'], ['Geeks']]\n\n# accessing an element from the\n# Multi-Dimensional List using\n# index number\nprint(\"Accessing a element from a Multi-Dimensional list\")\nprint(List[0][1])\nprint(List[1][0])\n","metadata":{"execution":{"iopub.status.busy":"2023-07-04T15:09:04.812882Z","iopub.execute_input":"2023-07-04T15:09:04.813792Z","iopub.status.idle":"2023-07-04T15:09:04.826749Z","shell.execute_reply.started":"2023-07-04T15:09:04.813741Z","shell.execute_reply":"2023-07-04T15:09:04.825433Z"},"trusted":true},"execution_count":18,"outputs":[{"name":"stdout","text":"Accessing a element from a Multi-Dimensional list\nFor\nGeeks\n","output_type":"stream"}]},{"cell_type":"code","source":"List = [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']\n\n# accessing an element using\n# negative indexing\nprint(\"Accessing element using negative indexing\")\n\n# print the last element of list\nprint(List[-1])\n\n# print the third last element of list\nprint(List[-3])\n","metadata":{"execution":{"iopub.status.busy":"2023-07-04T15:09:04.828326Z","iopub.execute_input":"2023-07-04T15:09:04.828792Z","iopub.status.idle":"2023-07-04T15:09:04.841823Z","shell.execute_reply.started":"2023-07-04T15:09:04.828741Z","shell.execute_reply":"2023-07-04T15:09:04.840323Z"},"trusted":true},"execution_count":19,"outputs":[{"name":"stdout","text":"Accessing element using negative indexing\nGeeks\nFor\n","output_type":"stream"}]},{"cell_type":"code","source":"# Creating a List\nList1 = []\nprint(len(List1))\n\n# Creating a List of numbers\nList2 = [10, 20, 14]\nprint(len(List2))\n","metadata":{"execution":{"iopub.status.busy":"2023-07-04T15:09:04.848352Z","iopub.execute_input":"2023-07-04T15:09:04.848788Z","iopub.status.idle":"2023-07-04T15:09:04.861954Z","shell.execute_reply.started":"2023-07-04T15:09:04.848757Z","shell.execute_reply":"2023-07-04T15:09:04.859926Z"},"trusted":true},"execution_count":20,"outputs":[{"name":"stdout","text":"0\n3\n","output_type":"stream"}]},{"cell_type":"code","source":"# Python program to take space\n# separated input as a string\n# split and store it to a list\n# and print the string list\n\n# input the list as string\nstring = input(\"Enter elements (Space-Separated): \")\n\n# split the strings and store it to a list\nlst = string.split()\nprint('The list is:', lst) # printing the list\n","metadata":{"execution":{"iopub.status.busy":"2023-07-04T15:09:04.863333Z","iopub.execute_input":"2023-07-04T15:09:04.863819Z","iopub.status.idle":"2023-07-04T15:09:11.232790Z","shell.execute_reply.started":"2023-07-04T15:09:04.863778Z","shell.execute_reply":"2023-07-04T15:09:11.231206Z"},"trusted":true},"execution_count":21,"outputs":[{"output_type":"stream","name":"stdin","text":"Enter elements (Space-Separated): sdffrf\n"},{"name":"stdout","text":"The list is: ['sdffrf']\n","output_type":"stream"}]},{"cell_type":"code","source":"# input size of the list\nn = int(input(\"Enter the size of list : \"))\n# store integers in a list using map,\n# split and strip functions\nlst = list(map(int, input(\"Enter the integer\\\nelements:\").strip().split()))[:n]\n\n# printing the list\nprint('The list is:', lst)\n","metadata":{"execution":{"iopub.status.busy":"2023-07-04T15:10:36.339990Z","iopub.execute_input":"2023-07-04T15:10:36.340458Z","iopub.status.idle":"2023-07-04T15:10:46.611550Z","shell.execute_reply.started":"2023-07-04T15:10:36.340423Z","shell.execute_reply":"2023-07-04T15:10:46.610297Z"},"trusted":true},"execution_count":24,"outputs":[{"output_type":"stream","name":"stdin","text":"Enter the size of list : 6\nEnter the integerelements: 456789\n"},{"name":"stdout","text":"The list is: [456789]\n","output_type":"stream"}]},{"cell_type":"code","source":"# Python program to demonstrate\n# Addition of elements in a List\n\n# Creating a List\nList = []\nprint(\"Initial blank List: \")\nprint(List)\n\n# Addition of Elements\n# in the List\nList.append(1)\nList.append(2)\nList.append(4)\nprint(\"\\nList after Addition of Three elements: \")\nprint(List)\n\n# Adding elements to the List\n# using Iterator\nfor i in range(1, 4):\n\tList.append(i)\nprint(\"\\nList after Addition of elements from 1-3: \")\nprint(List)\n\n# Adding Tuples to the List\nList.append((5, 6))\nprint(\"\\nList after Addition of a Tuple: \")\nprint(List)\n\n# Addition of List to a List\nList2 = ['For', 'Geeks']\nList.append(List2)\nprint(\"\\nList after Addition of a List: \")\nprint(List)\n","metadata":{"execution":{"iopub.status.busy":"2023-07-04T15:10:59.065964Z","iopub.execute_input":"2023-07-04T15:10:59.066426Z","iopub.status.idle":"2023-07-04T15:10:59.076434Z","shell.execute_reply.started":"2023-07-04T15:10:59.066390Z","shell.execute_reply":"2023-07-04T15:10:59.074827Z"},"trusted":true},"execution_count":25,"outputs":[{"name":"stdout","text":"Initial blank List: \n[]\n\nList after Addition of Three elements: \n[1, 2, 4]\n\nList after Addition of elements from 1-3: \n[1, 2, 4, 1, 2, 3]\n\nList after Addition of a Tuple: \n[1, 2, 4, 1, 2, 3, (5, 6)]\n\nList after Addition of a List: \n[1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]\n","output_type":"stream"}]},{"cell_type":"code","source":"# Python program to demonstrate\n# Addition of elements in a List\n\n# Creating a List\nList = [1,2,3,4]\nprint(\"Initial List: \")\nprint(List)\n\n# Addition of Element at\n# specific Position\n# (using Insert Method)\nList.insert(3, 12)\nList.insert(0, 'Google')\nprint(\"\\nList after performing Insert Operation: \")\nprint(List)\n","metadata":{"execution":{"iopub.status.busy":"2023-07-04T15:11:15.008350Z","iopub.execute_input":"2023-07-04T15:11:15.008765Z","iopub.status.idle":"2023-07-04T15:11:15.017203Z","shell.execute_reply.started":"2023-07-04T15:11:15.008735Z","shell.execute_reply":"2023-07-04T15:11:15.015592Z"},"trusted":true},"execution_count":27,"outputs":[{"name":"stdout","text":"Initial List: \n[1, 2, 3, 4]\n\nList after performing Insert Operation: \n['Google', 1, 2, 3, 12, 4]\n","output_type":"stream"}]},{"cell_type":"code","source":"# Python program to demonstrate\n# Addition of elements in a List\n\n# Creating a List\nList = [1, 2, 3, 4]\nprint(\"Initial List: \")\nprint(List)\n\n# Addition of multiple elements\n# to the List at the end\n# (using Extend Method)\nList.extend([8, 'Game', 'Always'])\nprint(\"\\nList after performing Extend Operation: \")\nprint(List)\n","metadata":{"execution":{"iopub.status.busy":"2023-07-04T15:11:23.057265Z","iopub.execute_input":"2023-07-04T15:11:23.058094Z","iopub.status.idle":"2023-07-04T15:11:23.065913Z","shell.execute_reply.started":"2023-07-04T15:11:23.057997Z","shell.execute_reply":"2023-07-04T15:11:23.064616Z"},"trusted":true},"execution_count":28,"outputs":[{"name":"stdout","text":"Initial List: \n[1, 2, 3, 4]\n\nList after performing Extend Operation: \n[1, 2, 3, 4, 8, 'Game', 'Always']\n","output_type":"stream"}]},{"cell_type":"code","source":"# Reversing a list\nmylist = [1, 2, 3, 4, 5, 'noodles', 'snake']\nmylist.reverse()\nprint(mylist)\n","metadata":{"execution":{"iopub.status.busy":"2023-07-04T15:11:39.749840Z","iopub.execute_input":"2023-07-04T15:11:39.750344Z","iopub.status.idle":"2023-07-04T15:11:39.757365Z","shell.execute_reply.started":"2023-07-04T15:11:39.750309Z","shell.execute_reply":"2023-07-04T15:11:39.755883Z"},"trusted":true},"execution_count":29,"outputs":[{"name":"stdout","text":"['snake', 'noodles', 5, 4, 3, 2, 1]\n","output_type":"stream"}]},{"cell_type":"code","source":"# Python program to demonstrate\n# Removal of elements in a List\n\n# Creating a List\nList = [1, 2, 3, 4, 5, 6,\n\t\t7, 8, 9, 10, 11, 12]\nprint(\"Initial List: \")\nprint(List)\n\n# Removing elements from List\n# using Remove() method\nList.remove(5)\nList.remove(6)\nprint(\"\\nList after Removal of two elements: \")\nprint(List)\n","metadata":{"execution":{"iopub.status.busy":"2023-07-04T15:11:48.447740Z","iopub.execute_input":"2023-07-04T15:11:48.448218Z","iopub.status.idle":"2023-07-04T15:11:48.455751Z","shell.execute_reply.started":"2023-07-04T15:11:48.448184Z","shell.execute_reply":"2023-07-04T15:11:48.454536Z"},"trusted":true},"execution_count":30,"outputs":[{"name":"stdout","text":"Initial List: \n[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]\n\nList after Removal of two elements: \n[1, 2, 3, 4, 7, 8, 9, 10, 11, 12]\n","output_type":"stream"}]},{"cell_type":"code","source":"# Creating a List\nList = [1, 2, 3, 4, 5, 6,\n\t\t7, 8, 9, 10, 11, 12]\n# Removing elements from List\n# using iterator method\nfor i in range(1, 5):\n\tList.remove(i)\nprint(\"\\nList after Removing a range of elements: \")\nprint(List)\n","metadata":{"execution":{"iopub.status.busy":"2023-07-04T15:11:53.798941Z","iopub.execute_input":"2023-07-04T15:11:53.799369Z","iopub.status.idle":"2023-07-04T15:11:53.807586Z","shell.execute_reply.started":"2023-07-04T15:11:53.799338Z","shell.execute_reply":"2023-07-04T15:11:53.806206Z"},"trusted":true},"execution_count":31,"outputs":[{"name":"stdout","text":"\nList after Removing a range of elements: \n[5, 6, 7, 8, 9, 10, 11, 12]\n","output_type":"stream"}]},{"cell_type":"code","source":"List = [1, 2, 3, 4, 5]\n\n# Removing element from the\n# Set using the pop() method\nList.pop()\nprint(\"\\nList after popping an element: \")\nprint(List)\n\n# Removing element at a\n# specific location from the\n# Set using the pop() method\nList.pop(2)\nprint(\"\\nList after popping a specific element: \")\nprint(List)\n","metadata":{"execution":{"iopub.status.busy":"2023-07-04T15:11:57.667843Z","iopub.execute_input":"2023-07-04T15:11:57.668326Z","iopub.status.idle":"2023-07-04T15:11:57.675810Z","shell.execute_reply.started":"2023-07-04T15:11:57.668290Z","shell.execute_reply":"2023-07-04T15:11:57.674797Z"},"trusted":true},"execution_count":32,"outputs":[{"name":"stdout","text":"\nList after popping an element: \n[1, 2, 3, 4]\n\nList after popping a specific element: \n[1, 2, 4]\n","output_type":"stream"}]},{"cell_type":"code","source":"# Python program to demonstrate list\n# comprehension in Python\n\n# below list contains square of all\n# odd numbers from range 1 to 10\nodd_square = [x ** 2 for x in range(1, 11) if x % 2 == 1]\nprint(odd_square)\n","metadata":{"execution":{"iopub.status.busy":"2023-07-04T15:12:01.470132Z","iopub.execute_input":"2023-07-04T15:12:01.470602Z","iopub.status.idle":"2023-07-04T15:12:01.478659Z","shell.execute_reply.started":"2023-07-04T15:12:01.470568Z","shell.execute_reply":"2023-07-04T15:12:01.476976Z"},"trusted":true},"execution_count":33,"outputs":[{"name":"stdout","text":"[1, 9, 25, 49, 81]\n","output_type":"stream"}]},{"cell_type":"code","source":"# for understanding, above generation is same as,\nodd_square = []\n\nfor x in range(1, 11):\n\tif x % 2 == 1:\n\t\todd_square.append(x**2)\n\nprint(odd_square)\n","metadata":{"execution":{"iopub.status.busy":"2023-07-04T15:12:04.698299Z","iopub.execute_input":"2023-07-04T15:12:04.698758Z","iopub.status.idle":"2023-07-04T15:12:04.705703Z","shell.execute_reply.started":"2023-07-04T15:12:04.698716Z","shell.execute_reply":"2023-07-04T15:12:04.704550Z"},"trusted":true},"execution_count":34,"outputs":[{"name":"stdout","text":"[1, 9, 25, 49, 81]\n","output_type":"stream"}]}]} --------------------------------------------------------------------------------