├── Excercises (1).zip ├── Introduction.ipynb ├── List Vs Tuple.ipynb ├── Lists and Tuples Questions.pdf ├── Loops-DataStructure.ipynb ├── Loops-DataStructure_2.ipynb ├── Operators and Loops Questions.pdf ├── README.md ├── String_Exercises.pdf ├── String_List_Methods.ipynb ├── String_Methods.ipynb ├── companytest.csv ├── cvs_fileformat.py ├── datetime_directives.txt ├── db_ops.py ├── definitions.ipynb ├── definitions_update.ipynb ├── excelr_junebatch.py ├── file_ops.py ├── json_ex.py ├── logging_ex.py ├── matplotlib.ipynb ├── modules.ipynb ├── numpy.ipynb ├── oops_abstraction.py ├── oops_encap.py ├── oops_encap_user4.py ├── oops_inheritance.py ├── pandas.ipynb ├── set.ipynb └── sys_example.py /Excercises (1).zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RaghulRameshTrainer/ExcelR_Python_08June2022/1f15cb1d4bbb1237219058b106a4e71d9c28c50a/Excercises (1).zip -------------------------------------------------------------------------------- /Introduction.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "id": "d7fb63dc", 7 | "metadata": {}, 8 | "outputs": [ 9 | { 10 | "data": { 11 | "text/plain": [ 12 | "11" 13 | ] 14 | }, 15 | "execution_count": 1, 16 | "metadata": {}, 17 | "output_type": "execute_result" 18 | } 19 | ], 20 | "source": [ 21 | "5+6 # Run" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 3, 27 | "id": "485418a9", 28 | "metadata": {}, 29 | "outputs": [ 30 | { 31 | "data": { 32 | "text/plain": [ 33 | "30" 34 | ] 35 | }, 36 | "execution_count": 3, 37 | "metadata": {}, 38 | "output_type": "execute_result" 39 | } 40 | ], 41 | "source": [ 42 | "5*6 # shift + enter" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 4, 48 | "id": "0b5221c0", 49 | "metadata": {}, 50 | "outputs": [ 51 | { 52 | "data": { 53 | "text/plain": [ 54 | "-1" 55 | ] 56 | }, 57 | "execution_count": 4, 58 | "metadata": {}, 59 | "output_type": "execute_result" 60 | } 61 | ], 62 | "source": [ 63 | "5-6 # ctrl + enter" 64 | ] 65 | }, 66 | { 67 | "cell_type": "markdown", 68 | "id": "30c13eb4", 69 | "metadata": {}, 70 | "source": [ 71 | "# Comments" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": 1, 77 | "id": "f3c44b43", 78 | "metadata": {}, 79 | "outputs": [ 80 | { 81 | "data": { 82 | "text/plain": [ 83 | "30" 84 | ] 85 | }, 86 | "execution_count": 1, 87 | "metadata": {}, 88 | "output_type": "execute_result" 89 | } 90 | ], 91 | "source": [ 92 | "# Single line comment\n", 93 | "\n", 94 | "# is used for commenting a line \n", 95 | "\n", 96 | "#add two numbers\n", 97 | "10+20" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": 2, 103 | "id": "2dee1fa2", 104 | "metadata": {}, 105 | "outputs": [ 106 | { 107 | "data": { 108 | "text/plain": [ 109 | "30" 110 | ] 111 | }, 112 | "execution_count": 2, 113 | "metadata": {}, 114 | "output_type": "execute_result" 115 | } 116 | ], 117 | "source": [ 118 | "\"\"\"\n", 119 | "Line1\n", 120 | "Line2\n", 121 | ".\n", 122 | ".\n", 123 | ".\n", 124 | "LineN\n", 125 | "\"\"\"\n", 126 | "\n", 127 | "5*6" 128 | ] 129 | }, 130 | { 131 | "cell_type": "markdown", 132 | "id": "9818e88f", 133 | "metadata": {}, 134 | "source": [ 135 | "# QUOTES" 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": null, 141 | "id": "472f6412", 142 | "metadata": {}, 143 | "outputs": [], 144 | "source": [ 145 | "'\n", 146 | "\"\n", 147 | "''' | \"\"\"" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": 3, 153 | "id": "31cc4d99", 154 | "metadata": {}, 155 | "outputs": [ 156 | { 157 | "name": "stdout", 158 | "output_type": "stream", 159 | "text": [ 160 | "Raghul Ramesh\n" 161 | ] 162 | } 163 | ], 164 | "source": [ 165 | "name='Raghul Ramesh'\n", 166 | "print(name)" 167 | ] 168 | }, 169 | { 170 | "cell_type": "code", 171 | "execution_count": 4, 172 | "id": "70ff20b6", 173 | "metadata": {}, 174 | "outputs": [ 175 | { 176 | "name": "stdout", 177 | "output_type": "stream", 178 | "text": [ 179 | "Raghul Ramesh\n" 180 | ] 181 | } 182 | ], 183 | "source": [ 184 | "name=\"Raghul Ramesh\"\n", 185 | "print(name)" 186 | ] 187 | }, 188 | { 189 | "cell_type": "code", 190 | "execution_count": 6, 191 | "id": "9fa53eb8", 192 | "metadata": {}, 193 | "outputs": [], 194 | "source": [ 195 | "college=\"st's joseph engg college\"" 196 | ] 197 | }, 198 | { 199 | "cell_type": "code", 200 | "execution_count": 7, 201 | "id": "2a92f15d", 202 | "metadata": {}, 203 | "outputs": [ 204 | { 205 | "name": "stdout", 206 | "output_type": "stream", 207 | "text": [ 208 | "st's joseph engg college\n" 209 | ] 210 | } 211 | ], 212 | "source": [ 213 | "print(college)" 214 | ] 215 | }, 216 | { 217 | "cell_type": "code", 218 | "execution_count": 8, 219 | "id": "a175b2ae", 220 | "metadata": {}, 221 | "outputs": [], 222 | "source": [ 223 | "college='st\\'s joseph engg college'" 224 | ] 225 | }, 226 | { 227 | "cell_type": "code", 228 | "execution_count": 9, 229 | "id": "f5571080", 230 | "metadata": {}, 231 | "outputs": [ 232 | { 233 | "name": "stdout", 234 | "output_type": "stream", 235 | "text": [ 236 | "st's joseph engg college\n" 237 | ] 238 | } 239 | ], 240 | "source": [ 241 | "print(college)" 242 | ] 243 | }, 244 | { 245 | "cell_type": "code", 246 | "execution_count": 11, 247 | "id": "5bd157b2", 248 | "metadata": {}, 249 | "outputs": [], 250 | "source": [ 251 | "about='Python support both \"Porcedural\" as well as \"OOPS\"'" 252 | ] 253 | }, 254 | { 255 | "cell_type": "code", 256 | "execution_count": 12, 257 | "id": "b21fdaa4", 258 | "metadata": {}, 259 | "outputs": [ 260 | { 261 | "name": "stdout", 262 | "output_type": "stream", 263 | "text": [ 264 | "Python support both \"Porcedural\" as well as \"OOPS\"\n" 265 | ] 266 | } 267 | ], 268 | "source": [ 269 | "print(about)" 270 | ] 271 | }, 272 | { 273 | "cell_type": "code", 274 | "execution_count": 17, 275 | "id": "9119efdd", 276 | "metadata": {}, 277 | "outputs": [], 278 | "source": [ 279 | "about='Python support both \\'Porcedural\\' as well as \"OOPS\"'" 280 | ] 281 | }, 282 | { 283 | "cell_type": "code", 284 | "execution_count": 18, 285 | "id": "6d09832e", 286 | "metadata": {}, 287 | "outputs": [ 288 | { 289 | "name": "stdout", 290 | "output_type": "stream", 291 | "text": [ 292 | "Python support both 'Porcedural' as well as \"OOPS\"\n" 293 | ] 294 | } 295 | ], 296 | "source": [ 297 | "print(about)" 298 | ] 299 | }, 300 | { 301 | "cell_type": "code", 302 | "execution_count": 26, 303 | "id": "434868b1", 304 | "metadata": {}, 305 | "outputs": [], 306 | "source": [ 307 | "about_python=\"\"\"Python is a high level, dynamic, procedural and object orietnted programming language\n", 308 | "It was developed by \"GUIDO VAN ROUSSUM\"\n", 309 | "He is from NETHERLAND\n", 310 | "It was releaed in to market on early 1990 \"\"\"" 311 | ] 312 | }, 313 | { 314 | "cell_type": "code", 315 | "execution_count": 30, 316 | "id": "c1e77613", 317 | "metadata": {}, 318 | "outputs": [ 319 | { 320 | "name": "stdout", 321 | "output_type": "stream", 322 | "text": [ 323 | "Python is a high level, dynamic, procedural and object orietnted programming language\n", 324 | "It was developed by \"GUIDO VAN ROUSSUM\"\n", 325 | "He is from NETHERLAND\n", 326 | "It was releaed in to market on early 1990 \n" 327 | ] 328 | } 329 | ], 330 | "source": [ 331 | "print(about_python)" 332 | ] 333 | }, 334 | { 335 | "cell_type": "code", 336 | "execution_count": 7, 337 | "id": "369f1cf9", 338 | "metadata": {}, 339 | "outputs": [ 340 | { 341 | "name": "stdout", 342 | "output_type": "stream", 343 | "text": [ 344 | "You can vote\n", 345 | "It is valid only for indian citizen\n", 346 | "Please check your own contry standards if you are from other country\n", 347 | "Out of conditional statement\n" 348 | ] 349 | } 350 | ], 351 | "source": [ 352 | "age=100\n", 353 | "if age>18 and age<=100:\n", 354 | " print(\"You can vote\")\n", 355 | " print(\"It is valid only for indian citizen\")\n", 356 | " print(\"Please check your own contry standards if you are from other country\")\n", 357 | "elif age<0 or age>100:\n", 358 | " print(\"Invalid age. Please check\")\n", 359 | "elif age==0:\n", 360 | " print(\"You are a just born baby!\")\n", 361 | "else:\n", 362 | " print(\"You cannot vote\")\n", 363 | " print(\"Because you are less than 18 years old\")\n", 364 | "print(\"Out of conditional statement\")" 365 | ] 366 | }, 367 | { 368 | "cell_type": "code", 369 | "execution_count": 10, 370 | "id": "bbac3ccf", 371 | "metadata": {}, 372 | "outputs": [ 373 | { 374 | "name": "stdout", 375 | "output_type": "stream", 376 | "text": [ 377 | "can't go for voting\n" 378 | ] 379 | } 380 | ], 381 | "source": [ 382 | "age=3\n", 383 | "country='India'\n", 384 | "\n", 385 | "if country == 'India':\n", 386 | " if age > 18:\n", 387 | " print(\"You are eligible to vote\")\n", 388 | " else:\n", 389 | " print(\"can't go for voting\")\n", 390 | "else:\n", 391 | " print(\"Please follow your own contry:{} standard\".format(country))" 392 | ] 393 | }, 394 | { 395 | "cell_type": "code", 396 | "execution_count": 15, 397 | "id": "d3027a9f", 398 | "metadata": {}, 399 | "outputs": [ 400 | { 401 | "name": "stdout", 402 | "output_type": "stream", 403 | "text": [ 404 | "-2\n" 405 | ] 406 | } 407 | ], 408 | "source": [ 409 | "age=-2\n", 410 | "if age>0:\n", 411 | " print(\"Your age is:\",age)\n", 412 | " \n", 413 | "elif age==100:\n", 414 | " print(\"Invalid age\")\n", 415 | " \n", 416 | "else:\n", 417 | " print(age)" 418 | ] 419 | }, 420 | { 421 | "cell_type": "code", 422 | "execution_count": null, 423 | "id": "ca7bcc87", 424 | "metadata": {}, 425 | "outputs": [], 426 | "source": [] 427 | } 428 | ], 429 | "metadata": { 430 | "kernelspec": { 431 | "display_name": "Python 3 (ipykernel)", 432 | "language": "python", 433 | "name": "python3" 434 | }, 435 | "language_info": { 436 | "codemirror_mode": { 437 | "name": "ipython", 438 | "version": 3 439 | }, 440 | "file_extension": ".py", 441 | "mimetype": "text/x-python", 442 | "name": "python", 443 | "nbconvert_exporter": "python", 444 | "pygments_lexer": "ipython3", 445 | "version": "3.8.10" 446 | } 447 | }, 448 | "nbformat": 4, 449 | "nbformat_minor": 5 450 | } 451 | -------------------------------------------------------------------------------- /List Vs Tuple.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 5, 6 | "id": "9912d83e", 7 | "metadata": {}, 8 | "outputs": [ 9 | { 10 | "data": { 11 | "text/plain": [ 12 | "'I am part of data engg visualization ML DL batch at excelR'" 13 | ] 14 | }, 15 | "execution_count": 5, 16 | "metadata": {}, 17 | "output_type": "execute_result" 18 | } 19 | ], 20 | "source": [ 21 | "str=\"I am part of data analytics batch at excelR\"\n", 22 | "str.replace('analytics','engg visualization ML DL')" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": 4, 28 | "id": "eb8db90f", 29 | "metadata": {}, 30 | "outputs": [ 31 | { 32 | "data": { 33 | "text/plain": [ 34 | "'I Am pArt of dAtA AnAlytiCs BAtCh At exCelR'" 35 | ] 36 | }, 37 | "execution_count": 4, 38 | "metadata": {}, 39 | "output_type": "execute_result" 40 | } 41 | ], 42 | "source": [ 43 | "#str.translate('abc','ABC')\n", 44 | "change=str.maketrans('abc','ABC')\n", 45 | "str.translate(change)" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": 10, 51 | "id": "be42858f", 52 | "metadata": {}, 53 | "outputs": [ 54 | { 55 | "data": { 56 | "text/plain": [ 57 | "'I am part of data analytics batch at excelR'" 58 | ] 59 | }, 60 | "execution_count": 10, 61 | "metadata": {}, 62 | "output_type": "execute_result" 63 | } 64 | ], 65 | "source": [ 66 | "str=\"I-am_part,of.data~analytics_batch-at~excelR\"\n", 67 | "changes=str.maketrans('.,~!@#$%^&*()_+-',' ' )\n", 68 | "str.translate(changes)" 69 | ] 70 | }, 71 | { 72 | "cell_type": "markdown", 73 | "id": "fc012acf", 74 | "metadata": {}, 75 | "source": [ 76 | "# TUPLE" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 11, 82 | "id": "209fc1d1", 83 | "metadata": {}, 84 | "outputs": [], 85 | "source": [ 86 | "x=[]" 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": 12, 92 | "id": "f00c15bc", 93 | "metadata": {}, 94 | "outputs": [ 95 | { 96 | "data": { 97 | "text/plain": [ 98 | "list" 99 | ] 100 | }, 101 | "execution_count": 12, 102 | "metadata": {}, 103 | "output_type": "execute_result" 104 | } 105 | ], 106 | "source": [ 107 | "type(x)" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": 13, 113 | "id": "192aeaf6", 114 | "metadata": {}, 115 | "outputs": [], 116 | "source": [ 117 | "x=()" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": 14, 123 | "id": "b90537d3", 124 | "metadata": {}, 125 | "outputs": [ 126 | { 127 | "data": { 128 | "text/plain": [ 129 | "tuple" 130 | ] 131 | }, 132 | "execution_count": 14, 133 | "metadata": {}, 134 | "output_type": "execute_result" 135 | } 136 | ], 137 | "source": [ 138 | "type(x)" 139 | ] 140 | }, 141 | { 142 | "cell_type": "code", 143 | "execution_count": 15, 144 | "id": "500bcc1f", 145 | "metadata": {}, 146 | "outputs": [], 147 | "source": [ 148 | "y=tuple()" 149 | ] 150 | }, 151 | { 152 | "cell_type": "code", 153 | "execution_count": 16, 154 | "id": "a5bc4cf4", 155 | "metadata": {}, 156 | "outputs": [ 157 | { 158 | "data": { 159 | "text/plain": [ 160 | "tuple" 161 | ] 162 | }, 163 | "execution_count": 16, 164 | "metadata": {}, 165 | "output_type": "execute_result" 166 | } 167 | ], 168 | "source": [ 169 | "type(y)" 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": 17, 175 | "id": "5753af7e", 176 | "metadata": {}, 177 | "outputs": [], 178 | "source": [ 179 | "data=('Wednesday','AIML',100,'ExcelR')" 180 | ] 181 | }, 182 | { 183 | "cell_type": "code", 184 | "execution_count": 19, 185 | "id": "a44bcef5", 186 | "metadata": {}, 187 | "outputs": [ 188 | { 189 | "data": { 190 | "text/plain": [ 191 | "tuple" 192 | ] 193 | }, 194 | "execution_count": 19, 195 | "metadata": {}, 196 | "output_type": "execute_result" 197 | } 198 | ], 199 | "source": [ 200 | "type(data)" 201 | ] 202 | }, 203 | { 204 | "cell_type": "code", 205 | "execution_count": 20, 206 | "id": "e8ea49ef", 207 | "metadata": {}, 208 | "outputs": [ 209 | { 210 | "data": { 211 | "text/plain": [ 212 | "4" 213 | ] 214 | }, 215 | "execution_count": 20, 216 | "metadata": {}, 217 | "output_type": "execute_result" 218 | } 219 | ], 220 | "source": [ 221 | "len(data)" 222 | ] 223 | }, 224 | { 225 | "cell_type": "code", 226 | "execution_count": 21, 227 | "id": "245afcdc", 228 | "metadata": {}, 229 | "outputs": [], 230 | "source": [ 231 | "nums=(32,5,8,3,79,55,45)" 232 | ] 233 | }, 234 | { 235 | "cell_type": "code", 236 | "execution_count": 22, 237 | "id": "18b99000", 238 | "metadata": {}, 239 | "outputs": [ 240 | { 241 | "data": { 242 | "text/plain": [ 243 | "3" 244 | ] 245 | }, 246 | "execution_count": 22, 247 | "metadata": {}, 248 | "output_type": "execute_result" 249 | } 250 | ], 251 | "source": [ 252 | "min(nums)" 253 | ] 254 | }, 255 | { 256 | "cell_type": "code", 257 | "execution_count": 23, 258 | "id": "76285b0a", 259 | "metadata": {}, 260 | "outputs": [ 261 | { 262 | "data": { 263 | "text/plain": [ 264 | "79" 265 | ] 266 | }, 267 | "execution_count": 23, 268 | "metadata": {}, 269 | "output_type": "execute_result" 270 | } 271 | ], 272 | "source": [ 273 | "max(nums)" 274 | ] 275 | }, 276 | { 277 | "cell_type": "code", 278 | "execution_count": 24, 279 | "id": "b96ca1a9", 280 | "metadata": {}, 281 | "outputs": [ 282 | { 283 | "data": { 284 | "text/plain": [ 285 | "227" 286 | ] 287 | }, 288 | "execution_count": 24, 289 | "metadata": {}, 290 | "output_type": "execute_result" 291 | } 292 | ], 293 | "source": [ 294 | "sum(nums)" 295 | ] 296 | }, 297 | { 298 | "cell_type": "code", 299 | "execution_count": null, 300 | "id": "cebfc433", 301 | "metadata": {}, 302 | "outputs": [], 303 | "source": [ 304 | "# append, extend , insert, pop, remove, sort, reverse, copy, clear, index, count" 305 | ] 306 | }, 307 | { 308 | "cell_type": "code", 309 | "execution_count": null, 310 | "id": "35a9f0db", 311 | "metadata": {}, 312 | "outputs": [], 313 | "source": [ 314 | "# index, count" 315 | ] 316 | }, 317 | { 318 | "cell_type": "code", 319 | "execution_count": 25, 320 | "id": "dd2035eb", 321 | "metadata": {}, 322 | "outputs": [ 323 | { 324 | "name": "stdout", 325 | "output_type": "stream", 326 | "text": [ 327 | "['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'count', 'index']\n" 328 | ] 329 | } 330 | ], 331 | "source": [ 332 | "print(dir(nums))" 333 | ] 334 | }, 335 | { 336 | "cell_type": "code", 337 | "execution_count": 62, 338 | "id": "71086dc4", 339 | "metadata": {}, 340 | "outputs": [], 341 | "source": [ 342 | "mytuple=('Python','R','SAS','Hadoop','Spark','Java','Python','Java','AIML')" 343 | ] 344 | }, 345 | { 346 | "cell_type": "code", 347 | "execution_count": 65, 348 | "id": "64294639", 349 | "metadata": {}, 350 | "outputs": [ 351 | { 352 | "data": { 353 | "text/plain": [ 354 | "'AIML'" 355 | ] 356 | }, 357 | "execution_count": 65, 358 | "metadata": {}, 359 | "output_type": "execute_result" 360 | } 361 | ], 362 | "source": [ 363 | "mytuple[-1]" 364 | ] 365 | }, 366 | { 367 | "cell_type": "code", 368 | "execution_count": 27, 369 | "id": "d67085db", 370 | "metadata": {}, 371 | "outputs": [ 372 | { 373 | "data": { 374 | "text/plain": [ 375 | "2" 376 | ] 377 | }, 378 | "execution_count": 27, 379 | "metadata": {}, 380 | "output_type": "execute_result" 381 | } 382 | ], 383 | "source": [ 384 | "mytuple.count('Python')" 385 | ] 386 | }, 387 | { 388 | "cell_type": "code", 389 | "execution_count": 29, 390 | "id": "5ca21e66", 391 | "metadata": {}, 392 | "outputs": [ 393 | { 394 | "data": { 395 | "text/plain": [ 396 | "2" 397 | ] 398 | }, 399 | "execution_count": 29, 400 | "metadata": {}, 401 | "output_type": "execute_result" 402 | } 403 | ], 404 | "source": [ 405 | "mytuple.index('SAS')" 406 | ] 407 | }, 408 | { 409 | "cell_type": "code", 410 | "execution_count": null, 411 | "id": "66c9493f", 412 | "metadata": {}, 413 | "outputs": [], 414 | "source": [ 415 | "List is Mutable Tuple is immutable\n", 416 | "[] ()\n", 417 | "List take more memory Tuple takes less memory\n", 418 | "List takes more time to process Tuple takes less time to process" 419 | ] 420 | }, 421 | { 422 | "cell_type": "code", 423 | "execution_count": 38, 424 | "id": "c6cc2638", 425 | "metadata": {}, 426 | "outputs": [ 427 | { 428 | "name": "stdout", 429 | "output_type": "stream", 430 | "text": [ 431 | "LIST SIZE: 136\n", 432 | "TUPLE SIZE: 120\n" 433 | ] 434 | } 435 | ], 436 | "source": [ 437 | "import sys\n", 438 | "\n", 439 | "print(\"LIST SIZE:\",sys.getsizeof([1,2,3,4,5,6,7,8,9,10]))\n", 440 | "print(\"TUPLE SIZE:\",sys.getsizeof((1,2,3,4,5,6,7,8,9,10)))" 441 | ] 442 | }, 443 | { 444 | "cell_type": "code", 445 | "execution_count": 37, 446 | "id": "5a8c7e56", 447 | "metadata": {}, 448 | "outputs": [ 449 | { 450 | "name": "stdout", 451 | "output_type": "stream", 452 | "text": [ 453 | "List takes: 80.64409999997224\n", 454 | "Tuple takes: 7.604899999932968\n" 455 | ] 456 | } 457 | ], 458 | "source": [ 459 | "import timeit\n", 460 | "\n", 461 | "print(\"List takes:\",timeit.timeit(stmt=\"[1,2,3,4,5,6,7,8,9,10]\",number=1000000)*1000)\n", 462 | "print(\"Tuple takes:\",timeit.timeit(stmt=\"(1,2,3,4,5,6,7,8,9,10)\",number=1000000)*1000)" 463 | ] 464 | }, 465 | { 466 | "cell_type": "code", 467 | "execution_count": null, 468 | "id": "8abb58e0", 469 | "metadata": {}, 470 | "outputs": [], 471 | "source": [ 472 | "HPC => High Performance Computers" 473 | ] 474 | }, 475 | { 476 | "cell_type": "code", 477 | "execution_count": 39, 478 | "id": "8579953a", 479 | "metadata": {}, 480 | "outputs": [], 481 | "source": [ 482 | "x=[1,2,3,4,5,6,7,8,9,10]" 483 | ] 484 | }, 485 | { 486 | "cell_type": "code", 487 | "execution_count": 40, 488 | "id": "7e02b540", 489 | "metadata": {}, 490 | "outputs": [ 491 | { 492 | "data": { 493 | "text/plain": [ 494 | "list" 495 | ] 496 | }, 497 | "execution_count": 40, 498 | "metadata": {}, 499 | "output_type": "execute_result" 500 | } 501 | ], 502 | "source": [ 503 | "type(x)" 504 | ] 505 | }, 506 | { 507 | "cell_type": "code", 508 | "execution_count": 41, 509 | "id": "6f169b19", 510 | "metadata": {}, 511 | "outputs": [], 512 | "source": [ 513 | "y=tuple(x)" 514 | ] 515 | }, 516 | { 517 | "cell_type": "code", 518 | "execution_count": 42, 519 | "id": "1e7841b0", 520 | "metadata": {}, 521 | "outputs": [ 522 | { 523 | "data": { 524 | "text/plain": [ 525 | "tuple" 526 | ] 527 | }, 528 | "execution_count": 42, 529 | "metadata": {}, 530 | "output_type": "execute_result" 531 | } 532 | ], 533 | "source": [ 534 | "type(y)" 535 | ] 536 | }, 537 | { 538 | "cell_type": "code", 539 | "execution_count": 43, 540 | "id": "18f09c4f", 541 | "metadata": {}, 542 | "outputs": [ 543 | { 544 | "data": { 545 | "text/plain": [ 546 | "(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)" 547 | ] 548 | }, 549 | "execution_count": 43, 550 | "metadata": {}, 551 | "output_type": "execute_result" 552 | } 553 | ], 554 | "source": [ 555 | "y" 556 | ] 557 | }, 558 | { 559 | "cell_type": "code", 560 | "execution_count": 48, 561 | "id": "426e42b8", 562 | "metadata": {}, 563 | "outputs": [], 564 | "source": [ 565 | "x=(10)\n", 566 | "y=[10]" 567 | ] 568 | }, 569 | { 570 | "cell_type": "code", 571 | "execution_count": 49, 572 | "id": "5c31cf6f", 573 | "metadata": {}, 574 | "outputs": [ 575 | { 576 | "data": { 577 | "text/plain": [ 578 | "list" 579 | ] 580 | }, 581 | "execution_count": 49, 582 | "metadata": {}, 583 | "output_type": "execute_result" 584 | } 585 | ], 586 | "source": [ 587 | "type(y)" 588 | ] 589 | }, 590 | { 591 | "cell_type": "code", 592 | "execution_count": 50, 593 | "id": "15305171", 594 | "metadata": {}, 595 | "outputs": [ 596 | { 597 | "data": { 598 | "text/plain": [ 599 | "int" 600 | ] 601 | }, 602 | "execution_count": 50, 603 | "metadata": {}, 604 | "output_type": "execute_result" 605 | } 606 | ], 607 | "source": [ 608 | "type(x)" 609 | ] 610 | }, 611 | { 612 | "cell_type": "code", 613 | "execution_count": 51, 614 | "id": "80359e6b", 615 | "metadata": {}, 616 | "outputs": [], 617 | "source": [ 618 | "city=('Chennai')" 619 | ] 620 | }, 621 | { 622 | "cell_type": "code", 623 | "execution_count": 52, 624 | "id": "4eacc5d6", 625 | "metadata": {}, 626 | "outputs": [ 627 | { 628 | "data": { 629 | "text/plain": [ 630 | "str" 631 | ] 632 | }, 633 | "execution_count": 52, 634 | "metadata": {}, 635 | "output_type": "execute_result" 636 | } 637 | ], 638 | "source": [ 639 | "type(city)" 640 | ] 641 | }, 642 | { 643 | "cell_type": "code", 644 | "execution_count": 53, 645 | "id": "6def60b4", 646 | "metadata": {}, 647 | "outputs": [], 648 | "source": [ 649 | "data=(10,20)" 650 | ] 651 | }, 652 | { 653 | "cell_type": "code", 654 | "execution_count": 54, 655 | "id": "258d670c", 656 | "metadata": {}, 657 | "outputs": [ 658 | { 659 | "data": { 660 | "text/plain": [ 661 | "tuple" 662 | ] 663 | }, 664 | "execution_count": 54, 665 | "metadata": {}, 666 | "output_type": "execute_result" 667 | } 668 | ], 669 | "source": [ 670 | "type(data)" 671 | ] 672 | }, 673 | { 674 | "cell_type": "code", 675 | "execution_count": 55, 676 | "id": "ce119ea9", 677 | "metadata": {}, 678 | "outputs": [], 679 | "source": [ 680 | "location=('Chennai','banagalore')" 681 | ] 682 | }, 683 | { 684 | "cell_type": "code", 685 | "execution_count": 56, 686 | "id": "82a10248", 687 | "metadata": {}, 688 | "outputs": [ 689 | { 690 | "data": { 691 | "text/plain": [ 692 | "tuple" 693 | ] 694 | }, 695 | "execution_count": 56, 696 | "metadata": {}, 697 | "output_type": "execute_result" 698 | } 699 | ], 700 | "source": [ 701 | "type(location)" 702 | ] 703 | }, 704 | { 705 | "cell_type": "code", 706 | "execution_count": 57, 707 | "id": "e82ca27c", 708 | "metadata": {}, 709 | "outputs": [], 710 | "source": [ 711 | "x=(10,)" 712 | ] 713 | }, 714 | { 715 | "cell_type": "code", 716 | "execution_count": 58, 717 | "id": "14bf6329", 718 | "metadata": {}, 719 | "outputs": [ 720 | { 721 | "data": { 722 | "text/plain": [ 723 | "tuple" 724 | ] 725 | }, 726 | "execution_count": 58, 727 | "metadata": {}, 728 | "output_type": "execute_result" 729 | } 730 | ], 731 | "source": [ 732 | "type(x)" 733 | ] 734 | }, 735 | { 736 | "cell_type": "code", 737 | "execution_count": 60, 738 | "id": "50372685", 739 | "metadata": {}, 740 | "outputs": [], 741 | "source": [ 742 | "c=('Chennai',)" 743 | ] 744 | }, 745 | { 746 | "cell_type": "code", 747 | "execution_count": 61, 748 | "id": "0fe49d4f", 749 | "metadata": {}, 750 | "outputs": [ 751 | { 752 | "data": { 753 | "text/plain": [ 754 | "tuple" 755 | ] 756 | }, 757 | "execution_count": 61, 758 | "metadata": {}, 759 | "output_type": "execute_result" 760 | } 761 | ], 762 | "source": [ 763 | "type(c)" 764 | ] 765 | }, 766 | { 767 | "cell_type": "markdown", 768 | "id": "4a408f5e", 769 | "metadata": {}, 770 | "source": [ 771 | "# DICTIONARY " 772 | ] 773 | }, 774 | { 775 | "cell_type": "code", 776 | "execution_count": null, 777 | "id": "7b29f718", 778 | "metadata": {}, 779 | "outputs": [], 780 | "source": [ 781 | "key value pairs of element\n", 782 | "it is unordered array\n", 783 | "dictionary|hash|hash map|associative array" 784 | ] 785 | }, 786 | { 787 | "cell_type": "code", 788 | "execution_count": 66, 789 | "id": "323e21f6", 790 | "metadata": {}, 791 | "outputs": [], 792 | "source": [ 793 | "mydata={}" 794 | ] 795 | }, 796 | { 797 | "cell_type": "code", 798 | "execution_count": 67, 799 | "id": "0826c570", 800 | "metadata": {}, 801 | "outputs": [ 802 | { 803 | "data": { 804 | "text/plain": [ 805 | "dict" 806 | ] 807 | }, 808 | "execution_count": 67, 809 | "metadata": {}, 810 | "output_type": "execute_result" 811 | } 812 | ], 813 | "source": [ 814 | "type(mydata)" 815 | ] 816 | }, 817 | { 818 | "cell_type": "code", 819 | "execution_count": 68, 820 | "id": "e1d20b23", 821 | "metadata": {}, 822 | "outputs": [], 823 | "source": [ 824 | "mydata={'today':'Wednesday','age':37,'tech':'python','company':'excelR'}" 825 | ] 826 | }, 827 | { 828 | "cell_type": "code", 829 | "execution_count": 73, 830 | "id": "d1b52252", 831 | "metadata": {}, 832 | "outputs": [ 833 | { 834 | "data": { 835 | "text/plain": [ 836 | "37" 837 | ] 838 | }, 839 | "execution_count": 73, 840 | "metadata": {}, 841 | "output_type": "execute_result" 842 | } 843 | ], 844 | "source": [ 845 | "mydata['age']" 846 | ] 847 | }, 848 | { 849 | "cell_type": "code", 850 | "execution_count": 70, 851 | "id": "0d0049ac", 852 | "metadata": {}, 853 | "outputs": [ 854 | { 855 | "data": { 856 | "text/plain": [ 857 | "'Wednesday'" 858 | ] 859 | }, 860 | "execution_count": 70, 861 | "metadata": {}, 862 | "output_type": "execute_result" 863 | } 864 | ], 865 | "source": [ 866 | "mydata['today']" 867 | ] 868 | }, 869 | { 870 | "cell_type": "code", 871 | "execution_count": 71, 872 | "id": "d0da0a36", 873 | "metadata": {}, 874 | "outputs": [ 875 | { 876 | "data": { 877 | "text/plain": [ 878 | "'python'" 879 | ] 880 | }, 881 | "execution_count": 71, 882 | "metadata": {}, 883 | "output_type": "execute_result" 884 | } 885 | ], 886 | "source": [ 887 | "mydata['tech']" 888 | ] 889 | }, 890 | { 891 | "cell_type": "code", 892 | "execution_count": 74, 893 | "id": "84e40513", 894 | "metadata": {}, 895 | "outputs": [ 896 | { 897 | "ename": "KeyError", 898 | "evalue": "'name'", 899 | "output_type": "error", 900 | "traceback": [ 901 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 902 | "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)", 903 | "Input \u001b[1;32mIn [74]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mmydata\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mname\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\n", 904 | "\u001b[1;31mKeyError\u001b[0m: 'name'" 905 | ] 906 | } 907 | ], 908 | "source": [ 909 | "mydata['name']" 910 | ] 911 | }, 912 | { 913 | "cell_type": "code", 914 | "execution_count": 75, 915 | "id": "f6b4c953", 916 | "metadata": {}, 917 | "outputs": [ 918 | { 919 | "data": { 920 | "text/plain": [ 921 | "37" 922 | ] 923 | }, 924 | "execution_count": 75, 925 | "metadata": {}, 926 | "output_type": "execute_result" 927 | } 928 | ], 929 | "source": [ 930 | "# get and setdefault\n", 931 | "\n", 932 | "mydata.get('age')" 933 | ] 934 | }, 935 | { 936 | "cell_type": "code", 937 | "execution_count": 76, 938 | "id": "f8f44494", 939 | "metadata": {}, 940 | "outputs": [ 941 | { 942 | "data": { 943 | "text/plain": [ 944 | "'excelR'" 945 | ] 946 | }, 947 | "execution_count": 76, 948 | "metadata": {}, 949 | "output_type": "execute_result" 950 | } 951 | ], 952 | "source": [ 953 | "mydata.get('company')" 954 | ] 955 | }, 956 | { 957 | "cell_type": "code", 958 | "execution_count": 78, 959 | "id": "9ec7b47f", 960 | "metadata": {}, 961 | "outputs": [ 962 | { 963 | "name": "stdout", 964 | "output_type": "stream", 965 | "text": [ 966 | "None\n" 967 | ] 968 | } 969 | ], 970 | "source": [ 971 | "print(mydata.get('name'))" 972 | ] 973 | }, 974 | { 975 | "cell_type": "code", 976 | "execution_count": 81, 977 | "id": "06fcfaef", 978 | "metadata": {}, 979 | "outputs": [ 980 | { 981 | "data": { 982 | "text/plain": [ 983 | "'Balamurugan'" 984 | ] 985 | }, 986 | "execution_count": 81, 987 | "metadata": {}, 988 | "output_type": "execute_result" 989 | } 990 | ], 991 | "source": [ 992 | "mydata.get('name','Balamurugan')" 993 | ] 994 | }, 995 | { 996 | "cell_type": "code", 997 | "execution_count": 82, 998 | "id": "19761589", 999 | "metadata": {}, 1000 | "outputs": [ 1001 | { 1002 | "data": { 1003 | "text/plain": [ 1004 | "{'today': 'Wednesday', 'age': 37, 'tech': 'python', 'company': 'excelR'}" 1005 | ] 1006 | }, 1007 | "execution_count": 82, 1008 | "metadata": {}, 1009 | "output_type": "execute_result" 1010 | } 1011 | ], 1012 | "source": [ 1013 | "mydata" 1014 | ] 1015 | }, 1016 | { 1017 | "cell_type": "code", 1018 | "execution_count": 83, 1019 | "id": "7b7e4ca5", 1020 | "metadata": {}, 1021 | "outputs": [ 1022 | { 1023 | "data": { 1024 | "text/plain": [ 1025 | "37" 1026 | ] 1027 | }, 1028 | "execution_count": 83, 1029 | "metadata": {}, 1030 | "output_type": "execute_result" 1031 | } 1032 | ], 1033 | "source": [ 1034 | "mydata.setdefault('age','Balamurugan')" 1035 | ] 1036 | }, 1037 | { 1038 | "cell_type": "code", 1039 | "execution_count": 84, 1040 | "id": "a0e369b8", 1041 | "metadata": {}, 1042 | "outputs": [ 1043 | { 1044 | "data": { 1045 | "text/plain": [ 1046 | "{'today': 'Wednesday', 'age': 37, 'tech': 'python', 'company': 'excelR'}" 1047 | ] 1048 | }, 1049 | "execution_count": 84, 1050 | "metadata": {}, 1051 | "output_type": "execute_result" 1052 | } 1053 | ], 1054 | "source": [ 1055 | "mydata" 1056 | ] 1057 | }, 1058 | { 1059 | "cell_type": "code", 1060 | "execution_count": 85, 1061 | "id": "8601522d", 1062 | "metadata": {}, 1063 | "outputs": [ 1064 | { 1065 | "data": { 1066 | "text/plain": [ 1067 | "'Balamurugan'" 1068 | ] 1069 | }, 1070 | "execution_count": 85, 1071 | "metadata": {}, 1072 | "output_type": "execute_result" 1073 | } 1074 | ], 1075 | "source": [ 1076 | "mydata.setdefault('name','Balamurugan')" 1077 | ] 1078 | }, 1079 | { 1080 | "cell_type": "code", 1081 | "execution_count": 87, 1082 | "id": "400e7d5b", 1083 | "metadata": {}, 1084 | "outputs": [ 1085 | { 1086 | "name": "stdout", 1087 | "output_type": "stream", 1088 | "text": [ 1089 | "{'today': 'Wednesday', 'age': 37, 'tech': 'python', 'company': 'excelR', 'name': 'Balamurugan'}\n" 1090 | ] 1091 | } 1092 | ], 1093 | "source": [ 1094 | "print(mydata)" 1095 | ] 1096 | }, 1097 | { 1098 | "cell_type": "code", 1099 | "execution_count": 88, 1100 | "id": "1d1f7702", 1101 | "metadata": {}, 1102 | "outputs": [], 1103 | "source": [ 1104 | "mydata['location']='Chennai'" 1105 | ] 1106 | }, 1107 | { 1108 | "cell_type": "code", 1109 | "execution_count": 89, 1110 | "id": "709c53f6", 1111 | "metadata": {}, 1112 | "outputs": [ 1113 | { 1114 | "name": "stdout", 1115 | "output_type": "stream", 1116 | "text": [ 1117 | "{'today': 'Wednesday', 'age': 37, 'tech': 'python', 'company': 'excelR', 'name': 'Balamurugan', 'location': 'Chennai'}\n" 1118 | ] 1119 | } 1120 | ], 1121 | "source": [ 1122 | "print(mydata)" 1123 | ] 1124 | }, 1125 | { 1126 | "cell_type": "code", 1127 | "execution_count": 90, 1128 | "id": "15d7ac92", 1129 | "metadata": {}, 1130 | "outputs": [], 1131 | "source": [ 1132 | "mydata['country']='India'" 1133 | ] 1134 | }, 1135 | { 1136 | "cell_type": "code", 1137 | "execution_count": 91, 1138 | "id": "4bea40c5", 1139 | "metadata": {}, 1140 | "outputs": [ 1141 | { 1142 | "name": "stdout", 1143 | "output_type": "stream", 1144 | "text": [ 1145 | "{'today': 'Wednesday', 'age': 37, 'tech': 'python', 'company': 'excelR', 'name': 'Balamurugan', 'location': 'Chennai', 'country': 'India'}\n" 1146 | ] 1147 | } 1148 | ], 1149 | "source": [ 1150 | "print(mydata)" 1151 | ] 1152 | }, 1153 | { 1154 | "cell_type": "code", 1155 | "execution_count": 92, 1156 | "id": "42b8eea9", 1157 | "metadata": {}, 1158 | "outputs": [], 1159 | "source": [ 1160 | "mydata['today']='Thursday'" 1161 | ] 1162 | }, 1163 | { 1164 | "cell_type": "code", 1165 | "execution_count": 93, 1166 | "id": "7e07a972", 1167 | "metadata": {}, 1168 | "outputs": [ 1169 | { 1170 | "name": "stdout", 1171 | "output_type": "stream", 1172 | "text": [ 1173 | "{'today': 'Thursday', 'age': 37, 'tech': 'python', 'company': 'excelR', 'name': 'Balamurugan', 'location': 'Chennai', 'country': 'India'}\n" 1174 | ] 1175 | } 1176 | ], 1177 | "source": [ 1178 | "print(mydata)" 1179 | ] 1180 | }, 1181 | { 1182 | "cell_type": "code", 1183 | "execution_count": 94, 1184 | "id": "8a114ead", 1185 | "metadata": {}, 1186 | "outputs": [], 1187 | "source": [ 1188 | "mydata.update({'salary':5000,'exp':10,'manager':'Nataraj','location':'Bangalore','tech':['Excel','Python','R','AI','Stats']})" 1189 | ] 1190 | }, 1191 | { 1192 | "cell_type": "code", 1193 | "execution_count": 95, 1194 | "id": "7c3e9434", 1195 | "metadata": {}, 1196 | "outputs": [ 1197 | { 1198 | "name": "stdout", 1199 | "output_type": "stream", 1200 | "text": [ 1201 | "{'today': 'Thursday', 'age': 37, 'tech': ['Excel', 'Python', 'R', 'AI', 'Stats'], 'company': 'excelR', 'name': 'Balamurugan', 'location': 'Bangalore', 'country': 'India', 'salary': 5000, 'exp': 10, 'manager': 'Nataraj'}\n" 1202 | ] 1203 | } 1204 | ], 1205 | "source": [ 1206 | "print(mydata)" 1207 | ] 1208 | }, 1209 | { 1210 | "cell_type": "code", 1211 | "execution_count": 96, 1212 | "id": "fe0a907c", 1213 | "metadata": {}, 1214 | "outputs": [], 1215 | "source": [ 1216 | "del mydata['today']" 1217 | ] 1218 | }, 1219 | { 1220 | "cell_type": "code", 1221 | "execution_count": 97, 1222 | "id": "dbac7f4a", 1223 | "metadata": {}, 1224 | "outputs": [ 1225 | { 1226 | "name": "stdout", 1227 | "output_type": "stream", 1228 | "text": [ 1229 | "{'age': 37, 'tech': ['Excel', 'Python', 'R', 'AI', 'Stats'], 'company': 'excelR', 'name': 'Balamurugan', 'location': 'Bangalore', 'country': 'India', 'salary': 5000, 'exp': 10, 'manager': 'Nataraj'}\n" 1230 | ] 1231 | } 1232 | ], 1233 | "source": [ 1234 | "print(mydata)" 1235 | ] 1236 | }, 1237 | { 1238 | "cell_type": "code", 1239 | "execution_count": 98, 1240 | "id": "62d183d3", 1241 | "metadata": {}, 1242 | "outputs": [ 1243 | { 1244 | "data": { 1245 | "text/plain": [ 1246 | "10" 1247 | ] 1248 | }, 1249 | "execution_count": 98, 1250 | "metadata": {}, 1251 | "output_type": "execute_result" 1252 | } 1253 | ], 1254 | "source": [ 1255 | "mydata.pop('exp')" 1256 | ] 1257 | }, 1258 | { 1259 | "cell_type": "code", 1260 | "execution_count": 99, 1261 | "id": "cda4f8eb", 1262 | "metadata": {}, 1263 | "outputs": [ 1264 | { 1265 | "name": "stdout", 1266 | "output_type": "stream", 1267 | "text": [ 1268 | "{'age': 37, 'tech': ['Excel', 'Python', 'R', 'AI', 'Stats'], 'company': 'excelR', 'name': 'Balamurugan', 'location': 'Bangalore', 'country': 'India', 'salary': 5000, 'manager': 'Nataraj'}\n" 1269 | ] 1270 | } 1271 | ], 1272 | "source": [ 1273 | "print(mydata)" 1274 | ] 1275 | }, 1276 | { 1277 | "cell_type": "code", 1278 | "execution_count": 100, 1279 | "id": "b5d760c4", 1280 | "metadata": {}, 1281 | "outputs": [ 1282 | { 1283 | "data": { 1284 | "text/plain": [ 1285 | "('manager', 'Nataraj')" 1286 | ] 1287 | }, 1288 | "execution_count": 100, 1289 | "metadata": {}, 1290 | "output_type": "execute_result" 1291 | } 1292 | ], 1293 | "source": [ 1294 | "mydata.popitem()" 1295 | ] 1296 | }, 1297 | { 1298 | "cell_type": "code", 1299 | "execution_count": 101, 1300 | "id": "3eb09542", 1301 | "metadata": {}, 1302 | "outputs": [ 1303 | { 1304 | "name": "stdout", 1305 | "output_type": "stream", 1306 | "text": [ 1307 | "{'age': 37, 'tech': ['Excel', 'Python', 'R', 'AI', 'Stats'], 'company': 'excelR', 'name': 'Balamurugan', 'location': 'Bangalore', 'country': 'India', 'salary': 5000}\n" 1308 | ] 1309 | } 1310 | ], 1311 | "source": [ 1312 | "print(mydata)" 1313 | ] 1314 | }, 1315 | { 1316 | "cell_type": "code", 1317 | "execution_count": 102, 1318 | "id": "7e1b7a07", 1319 | "metadata": {}, 1320 | "outputs": [ 1321 | { 1322 | "data": { 1323 | "text/plain": [ 1324 | "5000" 1325 | ] 1326 | }, 1327 | "execution_count": 102, 1328 | "metadata": {}, 1329 | "output_type": "execute_result" 1330 | } 1331 | ], 1332 | "source": [ 1333 | "mydata.pop('salary')" 1334 | ] 1335 | }, 1336 | { 1337 | "cell_type": "code", 1338 | "execution_count": 103, 1339 | "id": "45a8d10f", 1340 | "metadata": {}, 1341 | "outputs": [ 1342 | { 1343 | "name": "stdout", 1344 | "output_type": "stream", 1345 | "text": [ 1346 | "{'age': 37, 'tech': ['Excel', 'Python', 'R', 'AI', 'Stats'], 'company': 'excelR', 'name': 'Balamurugan', 'location': 'Bangalore', 'country': 'India'}\n" 1347 | ] 1348 | } 1349 | ], 1350 | "source": [ 1351 | "print(mydata)" 1352 | ] 1353 | }, 1354 | { 1355 | "cell_type": "code", 1356 | "execution_count": 105, 1357 | "id": "d190167c", 1358 | "metadata": {}, 1359 | "outputs": [ 1360 | { 1361 | "data": { 1362 | "text/plain": [ 1363 | "'Excel'" 1364 | ] 1365 | }, 1366 | "execution_count": 105, 1367 | "metadata": {}, 1368 | "output_type": "execute_result" 1369 | } 1370 | ], 1371 | "source": [ 1372 | "mydata['tech'].pop(0)" 1373 | ] 1374 | }, 1375 | { 1376 | "cell_type": "code", 1377 | "execution_count": 106, 1378 | "id": "94ad7d4c", 1379 | "metadata": {}, 1380 | "outputs": [ 1381 | { 1382 | "name": "stdout", 1383 | "output_type": "stream", 1384 | "text": [ 1385 | "{'age': 37, 'tech': ['Python', 'R', 'AI', 'Stats'], 'company': 'excelR', 'name': 'Balamurugan', 'location': 'Bangalore', 'country': 'India'}\n" 1386 | ] 1387 | } 1388 | ], 1389 | "source": [ 1390 | "print(mydata)" 1391 | ] 1392 | }, 1393 | { 1394 | "cell_type": "code", 1395 | "execution_count": null, 1396 | "id": "5c875a42", 1397 | "metadata": {}, 1398 | "outputs": [], 1399 | "source": [ 1400 | "#keys, values, items" 1401 | ] 1402 | }, 1403 | { 1404 | "cell_type": "code", 1405 | "execution_count": 107, 1406 | "id": "d52a3954", 1407 | "metadata": {}, 1408 | "outputs": [ 1409 | { 1410 | "data": { 1411 | "text/plain": [ 1412 | "{'age': 37,\n", 1413 | " 'tech': ['Python', 'R', 'AI', 'Stats'],\n", 1414 | " 'company': 'excelR',\n", 1415 | " 'name': 'Balamurugan',\n", 1416 | " 'location': 'Bangalore',\n", 1417 | " 'country': 'India'}" 1418 | ] 1419 | }, 1420 | "execution_count": 107, 1421 | "metadata": {}, 1422 | "output_type": "execute_result" 1423 | } 1424 | ], 1425 | "source": [ 1426 | "mydata" 1427 | ] 1428 | }, 1429 | { 1430 | "cell_type": "code", 1431 | "execution_count": 108, 1432 | "id": "5f0c8209", 1433 | "metadata": {}, 1434 | "outputs": [ 1435 | { 1436 | "data": { 1437 | "text/plain": [ 1438 | "dict_keys(['age', 'tech', 'company', 'name', 'location', 'country'])" 1439 | ] 1440 | }, 1441 | "execution_count": 108, 1442 | "metadata": {}, 1443 | "output_type": "execute_result" 1444 | } 1445 | ], 1446 | "source": [ 1447 | "mydata.keys()" 1448 | ] 1449 | }, 1450 | { 1451 | "cell_type": "code", 1452 | "execution_count": 109, 1453 | "id": "d3ad99b6", 1454 | "metadata": {}, 1455 | "outputs": [ 1456 | { 1457 | "data": { 1458 | "text/plain": [ 1459 | "dict_values([37, ['Python', 'R', 'AI', 'Stats'], 'excelR', 'Balamurugan', 'Bangalore', 'India'])" 1460 | ] 1461 | }, 1462 | "execution_count": 109, 1463 | "metadata": {}, 1464 | "output_type": "execute_result" 1465 | } 1466 | ], 1467 | "source": [ 1468 | "mydata.values()" 1469 | ] 1470 | }, 1471 | { 1472 | "cell_type": "code", 1473 | "execution_count": 110, 1474 | "id": "e663efec", 1475 | "metadata": {}, 1476 | "outputs": [ 1477 | { 1478 | "data": { 1479 | "text/plain": [ 1480 | "dict_items([('age', 37), ('tech', ['Python', 'R', 'AI', 'Stats']), ('company', 'excelR'), ('name', 'Balamurugan'), ('location', 'Bangalore'), ('country', 'India')])" 1481 | ] 1482 | }, 1483 | "execution_count": 110, 1484 | "metadata": {}, 1485 | "output_type": "execute_result" 1486 | } 1487 | ], 1488 | "source": [ 1489 | "mydata.items()" 1490 | ] 1491 | }, 1492 | { 1493 | "cell_type": "code", 1494 | "execution_count": 122, 1495 | "id": "d4691cdb", 1496 | "metadata": {}, 1497 | "outputs": [ 1498 | { 1499 | "data": { 1500 | "text/plain": [ 1501 | "['Python', 'R', 'AI', 'Stats']" 1502 | ] 1503 | }, 1504 | "execution_count": 122, 1505 | "metadata": {}, 1506 | "output_type": "execute_result" 1507 | } 1508 | ], 1509 | "source": [ 1510 | "mydata.pop('tech')" 1511 | ] 1512 | }, 1513 | { 1514 | "cell_type": "code", 1515 | "execution_count": 126, 1516 | "id": "62125865", 1517 | "metadata": {}, 1518 | "outputs": [ 1519 | { 1520 | "name": "stdout", 1521 | "output_type": "stream", 1522 | "text": [ 1523 | "company ===> excelR\n", 1524 | "name ===> Balamurugan\n", 1525 | "location ===> Bangalore\n", 1526 | "country ===> India\n" 1527 | ] 1528 | } 1529 | ], 1530 | "source": [ 1531 | "for k in mydata.keys():\n", 1532 | " print(k +\" ===> \"+ str(mydata[k]))" 1533 | ] 1534 | }, 1535 | { 1536 | "cell_type": "code", 1537 | "execution_count": 127, 1538 | "id": "8ebcebac", 1539 | "metadata": {}, 1540 | "outputs": [], 1541 | "source": [ 1542 | "mydata['age']=37" 1543 | ] 1544 | }, 1545 | { 1546 | "cell_type": "code", 1547 | "execution_count": 132, 1548 | "id": "75321454", 1549 | "metadata": {}, 1550 | "outputs": [ 1551 | { 1552 | "name": "stdout", 1553 | "output_type": "stream", 1554 | "text": [ 1555 | "excelR\n", 1556 | "Balamurugan\n", 1557 | "Bangalore\n", 1558 | "India\n", 1559 | "37\n" 1560 | ] 1561 | } 1562 | ], 1563 | "source": [ 1564 | "for k in mydata.keys():\n", 1565 | " print(mydata[k] )" 1566 | ] 1567 | }, 1568 | { 1569 | "cell_type": "code", 1570 | "execution_count": 134, 1571 | "id": "05ea3e7f", 1572 | "metadata": {}, 1573 | "outputs": [ 1574 | { 1575 | "name": "stdout", 1576 | "output_type": "stream", 1577 | "text": [ 1578 | "excelR\n", 1579 | "Balamurugan\n", 1580 | "Bangalore\n", 1581 | "India\n", 1582 | "37\n" 1583 | ] 1584 | } 1585 | ], 1586 | "source": [ 1587 | "for v in mydata.values():\n", 1588 | " print(mydata[v])" 1589 | ] 1590 | }, 1591 | { 1592 | "cell_type": "code", 1593 | "execution_count": 135, 1594 | "id": "8a0d591d", 1595 | "metadata": {}, 1596 | "outputs": [ 1597 | { 1598 | "data": { 1599 | "text/plain": [ 1600 | "dict_items([('company', 'excelR'), ('name', 'Balamurugan'), ('location', 'Bangalore'), ('country', 'India'), ('age', 37)])" 1601 | ] 1602 | }, 1603 | "execution_count": 135, 1604 | "metadata": {}, 1605 | "output_type": "execute_result" 1606 | } 1607 | ], 1608 | "source": [ 1609 | "mydata.items()" 1610 | ] 1611 | }, 1612 | { 1613 | "cell_type": "code", 1614 | "execution_count": 138, 1615 | "id": "16d707df", 1616 | "metadata": {}, 1617 | "outputs": [ 1618 | { 1619 | "name": "stdout", 1620 | "output_type": "stream", 1621 | "text": [ 1622 | "company excelR\n", 1623 | "name Balamurugan\n", 1624 | "location Bangalore\n", 1625 | "country India\n", 1626 | "age 37\n" 1627 | ] 1628 | } 1629 | ], 1630 | "source": [ 1631 | "for x , y in mydata.items():\n", 1632 | " print(x, y)" 1633 | ] 1634 | }, 1635 | { 1636 | "cell_type": "code", 1637 | "execution_count": 139, 1638 | "id": "efb7eddb", 1639 | "metadata": {}, 1640 | "outputs": [ 1641 | { 1642 | "name": "stdout", 1643 | "output_type": "stream", 1644 | "text": [ 1645 | "['__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values']\n" 1646 | ] 1647 | } 1648 | ], 1649 | "source": [ 1650 | "print(dir(mydata))" 1651 | ] 1652 | }, 1653 | { 1654 | "cell_type": "code", 1655 | "execution_count": 168, 1656 | "id": "e039d19d", 1657 | "metadata": {}, 1658 | "outputs": [], 1659 | "source": [ 1660 | "empdata={'fname','lname','age','degree','exp','gender','address'}" 1661 | ] 1662 | }, 1663 | { 1664 | "cell_type": "code", 1665 | "execution_count": 169, 1666 | "id": "f75096c5", 1667 | "metadata": {}, 1668 | "outputs": [], 1669 | "source": [ 1670 | "emp_info=dict.fromkeys(empdata,'ExcelR')" 1671 | ] 1672 | }, 1673 | { 1674 | "cell_type": "code", 1675 | "execution_count": 170, 1676 | "id": "1566e03a", 1677 | "metadata": {}, 1678 | "outputs": [ 1679 | { 1680 | "data": { 1681 | "text/plain": [ 1682 | "{'degree': 'ExcelR',\n", 1683 | " 'exp': 'ExcelR',\n", 1684 | " 'lname': 'ExcelR',\n", 1685 | " 'age': 'ExcelR',\n", 1686 | " 'address': 'ExcelR',\n", 1687 | " 'gender': 'ExcelR',\n", 1688 | " 'fname': 'ExcelR'}" 1689 | ] 1690 | }, 1691 | "execution_count": 170, 1692 | "metadata": {}, 1693 | "output_type": "execute_result" 1694 | } 1695 | ], 1696 | "source": [ 1697 | "emp_info" 1698 | ] 1699 | }, 1700 | { 1701 | "cell_type": "code", 1702 | "execution_count": 145, 1703 | "id": "25b2fbd8", 1704 | "metadata": {}, 1705 | "outputs": [], 1706 | "source": [ 1707 | "sample_dict={\n", 1708 | " 'name':'Raghul Ramesh',\n", 1709 | " 'age':37,\n", 1710 | " 'exp':{\n", 1711 | " 'infosys':['Python','Perl','Java'],\n", 1712 | " 'Paypal':['Python','AIML','AWS'],\n", 1713 | " 'walmart':['AIML',['AWS','GCP']],\n", 1714 | " 'Shell':['BigData','Snowflakes'],\n", 1715 | " 'Amazon':['Bigdata','AWS']\n", 1716 | " }\n", 1717 | "}" 1718 | ] 1719 | }, 1720 | { 1721 | "cell_type": "code", 1722 | "execution_count": 150, 1723 | "id": "a63f3bf9", 1724 | "metadata": {}, 1725 | "outputs": [ 1726 | { 1727 | "data": { 1728 | "text/plain": [ 1729 | "'GCP'" 1730 | ] 1731 | }, 1732 | "execution_count": 150, 1733 | "metadata": {}, 1734 | "output_type": "execute_result" 1735 | } 1736 | ], 1737 | "source": [ 1738 | "sample_dict.get('exp').get('walmart')[1][-1]" 1739 | ] 1740 | }, 1741 | { 1742 | "cell_type": "code", 1743 | "execution_count": 153, 1744 | "id": "a55d80ad", 1745 | "metadata": {}, 1746 | "outputs": [], 1747 | "source": [ 1748 | "myset=set()" 1749 | ] 1750 | }, 1751 | { 1752 | "cell_type": "code", 1753 | "execution_count": 154, 1754 | "id": "cc9c6c65", 1755 | "metadata": {}, 1756 | "outputs": [ 1757 | { 1758 | "data": { 1759 | "text/plain": [ 1760 | "set" 1761 | ] 1762 | }, 1763 | "execution_count": 154, 1764 | "metadata": {}, 1765 | "output_type": "execute_result" 1766 | } 1767 | ], 1768 | "source": [ 1769 | "type(myset)" 1770 | ] 1771 | }, 1772 | { 1773 | "cell_type": "code", 1774 | "execution_count": 155, 1775 | "id": "e91996c1", 1776 | "metadata": {}, 1777 | "outputs": [], 1778 | "source": [ 1779 | "myset={1,3,4,2,3,4,3,2,5,6,5,4,9,10,6,8,7,4,2,5,3,1,3,1,1,1}" 1780 | ] 1781 | }, 1782 | { 1783 | "cell_type": "code", 1784 | "execution_count": 156, 1785 | "id": "ce2b1a2e", 1786 | "metadata": {}, 1787 | "outputs": [ 1788 | { 1789 | "data": { 1790 | "text/plain": [ 1791 | "{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}" 1792 | ] 1793 | }, 1794 | "execution_count": 156, 1795 | "metadata": {}, 1796 | "output_type": "execute_result" 1797 | } 1798 | ], 1799 | "source": [ 1800 | "myset" 1801 | ] 1802 | }, 1803 | { 1804 | "cell_type": "code", 1805 | "execution_count": 157, 1806 | "id": "dfee0f59", 1807 | "metadata": {}, 1808 | "outputs": [], 1809 | "source": [ 1810 | "myset.add(11)" 1811 | ] 1812 | }, 1813 | { 1814 | "cell_type": "code", 1815 | "execution_count": 158, 1816 | "id": "f35ff30c", 1817 | "metadata": {}, 1818 | "outputs": [ 1819 | { 1820 | "data": { 1821 | "text/plain": [ 1822 | "{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}" 1823 | ] 1824 | }, 1825 | "execution_count": 158, 1826 | "metadata": {}, 1827 | "output_type": "execute_result" 1828 | } 1829 | ], 1830 | "source": [ 1831 | "myset" 1832 | ] 1833 | }, 1834 | { 1835 | "cell_type": "code", 1836 | "execution_count": 159, 1837 | "id": "11242931", 1838 | "metadata": {}, 1839 | "outputs": [], 1840 | "source": [ 1841 | "myset.add(15)" 1842 | ] 1843 | }, 1844 | { 1845 | "cell_type": "code", 1846 | "execution_count": 160, 1847 | "id": "99bb86c4", 1848 | "metadata": {}, 1849 | "outputs": [ 1850 | { 1851 | "data": { 1852 | "text/plain": [ 1853 | "{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 15}" 1854 | ] 1855 | }, 1856 | "execution_count": 160, 1857 | "metadata": {}, 1858 | "output_type": "execute_result" 1859 | } 1860 | ], 1861 | "source": [ 1862 | "myset" 1863 | ] 1864 | }, 1865 | { 1866 | "cell_type": "code", 1867 | "execution_count": 161, 1868 | "id": "fc97741d", 1869 | "metadata": {}, 1870 | "outputs": [], 1871 | "source": [ 1872 | "myset.add(13)" 1873 | ] 1874 | }, 1875 | { 1876 | "cell_type": "code", 1877 | "execution_count": 162, 1878 | "id": "9c0cc055", 1879 | "metadata": {}, 1880 | "outputs": [ 1881 | { 1882 | "data": { 1883 | "text/plain": [ 1884 | "{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15}" 1885 | ] 1886 | }, 1887 | "execution_count": 162, 1888 | "metadata": {}, 1889 | "output_type": "execute_result" 1890 | } 1891 | ], 1892 | "source": [ 1893 | "myset" 1894 | ] 1895 | }, 1896 | { 1897 | "cell_type": "code", 1898 | "execution_count": 163, 1899 | "id": "161a3bab", 1900 | "metadata": {}, 1901 | "outputs": [], 1902 | "source": [ 1903 | "myset.add(10)" 1904 | ] 1905 | }, 1906 | { 1907 | "cell_type": "code", 1908 | "execution_count": 164, 1909 | "id": "cc08ba5c", 1910 | "metadata": {}, 1911 | "outputs": [ 1912 | { 1913 | "data": { 1914 | "text/plain": [ 1915 | "{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15}" 1916 | ] 1917 | }, 1918 | "execution_count": 164, 1919 | "metadata": {}, 1920 | "output_type": "execute_result" 1921 | } 1922 | ], 1923 | "source": [ 1924 | "myset" 1925 | ] 1926 | }, 1927 | { 1928 | "cell_type": "code", 1929 | "execution_count": 173, 1930 | "id": "d0de727b", 1931 | "metadata": {}, 1932 | "outputs": [ 1933 | { 1934 | "name": "stdout", 1935 | "output_type": "stream", 1936 | "text": [ 1937 | "['__and__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__iand__', '__init__', '__init_subclass__', '__ior__', '__isub__', '__iter__', '__ixor__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__or__', '__rand__', '__reduce__', '__reduce_ex__', '__repr__', '__ror__', '__rsub__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__xor__', 'add', 'clear', 'copy', 'difference', 'difference_update', 'discard', 'intersection', 'intersection_update', 'isdisjoint', 'issubset', 'issuperset', 'pop', 'remove', 'symmetric_difference', 'symmetric_difference_update', 'union', 'update']\n" 1938 | ] 1939 | } 1940 | ], 1941 | "source": [ 1942 | "print(dir(myset))" 1943 | ] 1944 | }, 1945 | { 1946 | "cell_type": "code", 1947 | "execution_count": 175, 1948 | "id": "0b75e73e", 1949 | "metadata": {}, 1950 | "outputs": [ 1951 | { 1952 | "data": { 1953 | "text/plain": [ 1954 | "{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15}" 1955 | ] 1956 | }, 1957 | "execution_count": 175, 1958 | "metadata": {}, 1959 | "output_type": "execute_result" 1960 | } 1961 | ], 1962 | "source": [ 1963 | "myset" 1964 | ] 1965 | }, 1966 | { 1967 | "cell_type": "code", 1968 | "execution_count": 179, 1969 | "id": "8233d3b3", 1970 | "metadata": {}, 1971 | "outputs": [ 1972 | { 1973 | "data": { 1974 | "text/plain": [ 1975 | "15" 1976 | ] 1977 | }, 1978 | "execution_count": 179, 1979 | "metadata": {}, 1980 | "output_type": "execute_result" 1981 | } 1982 | ], 1983 | "source": [ 1984 | "list(myset)[-1]" 1985 | ] 1986 | }, 1987 | { 1988 | "cell_type": "code", 1989 | "execution_count": 183, 1990 | "id": "44815344", 1991 | "metadata": {}, 1992 | "outputs": [ 1993 | { 1994 | "name": "stdout", 1995 | "output_type": "stream", 1996 | "text": [ 1997 | "Enter a value and exit for come out:EXIT\n" 1998 | ] 1999 | } 2000 | ], 2001 | "source": [ 2002 | "while True:\n", 2003 | " data=input(\"Enter a value and exit for come out:\")\n", 2004 | " if data.casefold()=='exit':\n", 2005 | " break\n", 2006 | " print(\"Value:\", data)" 2007 | ] 2008 | }, 2009 | { 2010 | "cell_type": "code", 2011 | "execution_count": null, 2012 | "id": "660e64ae", 2013 | "metadata": {}, 2014 | "outputs": [], 2015 | "source": [] 2016 | } 2017 | ], 2018 | "metadata": { 2019 | "kernelspec": { 2020 | "display_name": "Python 3 (ipykernel)", 2021 | "language": "python", 2022 | "name": "python3" 2023 | }, 2024 | "language_info": { 2025 | "codemirror_mode": { 2026 | "name": "ipython", 2027 | "version": 3 2028 | }, 2029 | "file_extension": ".py", 2030 | "mimetype": "text/x-python", 2031 | "name": "python", 2032 | "nbconvert_exporter": "python", 2033 | "pygments_lexer": "ipython3", 2034 | "version": "3.8.10" 2035 | } 2036 | }, 2037 | "nbformat": 4, 2038 | "nbformat_minor": 5 2039 | } 2040 | -------------------------------------------------------------------------------- /Lists and Tuples Questions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RaghulRameshTrainer/ExcelR_Python_08June2022/1f15cb1d4bbb1237219058b106a4e71d9c28c50a/Lists and Tuples Questions.pdf -------------------------------------------------------------------------------- /Loops-DataStructure.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "f1b4eb44", 6 | "metadata": {}, 7 | "source": [ 8 | "# print functions" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "id": "3c223db5", 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "Hello\n" 22 | ] 23 | } 24 | ], 25 | "source": [ 26 | "print(\"Hello\")" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": 2, 32 | "id": "1783bebb", 33 | "metadata": {}, 34 | "outputs": [], 35 | "source": [ 36 | "name='Raghul Ramesh'" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 3, 42 | "id": "6b014959", 43 | "metadata": {}, 44 | "outputs": [ 45 | { 46 | "name": "stdout", 47 | "output_type": "stream", 48 | "text": [ 49 | "name\n" 50 | ] 51 | } 52 | ], 53 | "source": [ 54 | "print('name')" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": 4, 60 | "id": "e0cbe74e", 61 | "metadata": {}, 62 | "outputs": [ 63 | { 64 | "name": "stdout", 65 | "output_type": "stream", 66 | "text": [ 67 | "Raghul Ramesh\n" 68 | ] 69 | } 70 | ], 71 | "source": [ 72 | "print(name)" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": 5, 78 | "id": "6aae1fb2", 79 | "metadata": {}, 80 | "outputs": [ 81 | { 82 | "name": "stdout", 83 | "output_type": "stream", 84 | "text": [ 85 | "Trainer name is : name\n" 86 | ] 87 | } 88 | ], 89 | "source": [ 90 | "print('Trainer name is : name')" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 6, 96 | "id": "b106b3c9", 97 | "metadata": {}, 98 | "outputs": [ 99 | { 100 | "name": "stdout", 101 | "output_type": "stream", 102 | "text": [ 103 | "Trainer name is : Raghul Ramesh\n" 104 | ] 105 | } 106 | ], 107 | "source": [ 108 | "print('Trainer name is : ',name)" 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": 7, 114 | "id": "f1c0ab02", 115 | "metadata": {}, 116 | "outputs": [ 117 | { 118 | "name": "stdout", 119 | "output_type": "stream", 120 | "text": [ 121 | "Trainer name is Raghul Ramesh and he is 37 years old\n" 122 | ] 123 | } 124 | ], 125 | "source": [ 126 | "name='Raghul Ramesh'\n", 127 | "age=37\n", 128 | "city='Chennai'\n", 129 | "\n", 130 | "#Trainer name is Raghul Ramesh and he is 37 years old\n", 131 | "\n", 132 | "print(\"Trainer name is \", name , \"and he is \", age , \"years old\")" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": 8, 138 | "id": "1af88384", 139 | "metadata": {}, 140 | "outputs": [ 141 | { 142 | "name": "stdout", 143 | "output_type": "stream", 144 | "text": [ 145 | "Trainer name is Raghul Ramesh and he is 37 years old and he is from Chennai\n" 146 | ] 147 | } 148 | ], 149 | "source": [ 150 | "print(\"Trainer name is {} and he is {} years old and he is from {}\".format(name,age,city))" 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "execution_count": 9, 156 | "id": "c641c93e", 157 | "metadata": {}, 158 | "outputs": [ 159 | { 160 | "name": "stdout", 161 | "output_type": "stream", 162 | "text": [ 163 | "Trainer name is Raghul Ramesh and he is 37 years old and he is from Chennai\n" 164 | ] 165 | } 166 | ], 167 | "source": [ 168 | "print(f\"Trainer name is {name} and he is {age} years old and he is from {city}\")" 169 | ] 170 | }, 171 | { 172 | "cell_type": "code", 173 | "execution_count": 10, 174 | "id": "4d4081a1", 175 | "metadata": {}, 176 | "outputs": [ 177 | { 178 | "name": "stdout", 179 | "output_type": "stream", 180 | "text": [ 181 | "Trainer name is Raghul Ramesh and he is 37 years old and he is from Chennai\n" 182 | ] 183 | } 184 | ], 185 | "source": [ 186 | "print(\"Trainer name is {2} and he is {0} years old and he is from {1}\".format(age,city,name))" 187 | ] 188 | }, 189 | { 190 | "cell_type": "code", 191 | "execution_count": 11, 192 | "id": "26e32bcc", 193 | "metadata": {}, 194 | "outputs": [ 195 | { 196 | "name": "stdout", 197 | "output_type": "stream", 198 | "text": [ 199 | "The product's price is : 565.659\n" 200 | ] 201 | } 202 | ], 203 | "source": [ 204 | "price=565.6587432\n", 205 | "print(\"The product's price is : {0:.3f}\".format(price))" 206 | ] 207 | }, 208 | { 209 | "cell_type": "code", 210 | "execution_count": 12, 211 | "id": "595d116f", 212 | "metadata": {}, 213 | "outputs": [ 214 | { 215 | "data": { 216 | "text/plain": [ 217 | "565.659" 218 | ] 219 | }, 220 | "execution_count": 12, 221 | "metadata": {}, 222 | "output_type": "execute_result" 223 | } 224 | ], 225 | "source": [ 226 | "round(price,3)" 227 | ] 228 | }, 229 | { 230 | "cell_type": "code", 231 | "execution_count": 13, 232 | "id": "8fdc0bc5", 233 | "metadata": {}, 234 | "outputs": [ 235 | { 236 | "name": "stdout", 237 | "output_type": "stream", 238 | "text": [ 239 | "The product's price is : 565.66\n" 240 | ] 241 | } 242 | ], 243 | "source": [ 244 | "print(\"The product's price is : {}\".format(round(price,2)))" 245 | ] 246 | }, 247 | { 248 | "cell_type": "markdown", 249 | "id": "3520948a", 250 | "metadata": {}, 251 | "source": [ 252 | "# input function" 253 | ] 254 | }, 255 | { 256 | "cell_type": "code", 257 | "execution_count": 14, 258 | "id": "b561f492", 259 | "metadata": {}, 260 | "outputs": [ 261 | { 262 | "name": "stdout", 263 | "output_type": "stream", 264 | "text": [ 265 | "Enter your name:Raghul Ramesh\n", 266 | "Enter your age:37\n", 267 | "The type of name is : \n", 268 | "The type of age is : \n", 269 | "Age is: 38\n" 270 | ] 271 | } 272 | ], 273 | "source": [ 274 | "name=input(\"Enter your name:\")\n", 275 | "age=int(input(\"Enter your age:\"))\n", 276 | "age=age+1\n", 277 | "print(\"The type of name is :\", type(name))\n", 278 | "print(\"The type of age is :\", type(age))\n", 279 | "print(\"Age is:\",age)" 280 | ] 281 | }, 282 | { 283 | "cell_type": "code", 284 | "execution_count": 15, 285 | "id": "b63b0bb8", 286 | "metadata": {}, 287 | "outputs": [ 288 | { 289 | "name": "stdout", 290 | "output_type": "stream", 291 | "text": [ 292 | "Enter your account number:43728734432\n", 293 | "Enter your name:Raghul Ramesh\n", 294 | "Enter 4 digit pin:44542\n", 295 | "43728734432,Raghul Ramesh,44542\n", 296 | "Type of acct:, name: and pin:\n" 297 | ] 298 | } 299 | ], 300 | "source": [ 301 | "acct=input(\"Enter your account number:\")\n", 302 | "name=input(\"Enter your name:\")\n", 303 | "pin=int(input(\"Enter 4 digit pin:\"))\n", 304 | "\n", 305 | "print(\"{},{},{}\".format(acct,name,pin))\n", 306 | "print(\"Type of acct:{}, name:{} and pin:{}\".format(type(acct),type(name),type(pin)))" 307 | ] 308 | }, 309 | { 310 | "cell_type": "markdown", 311 | "id": "07c2de6d", 312 | "metadata": {}, 313 | "source": [ 314 | "# range function" 315 | ] 316 | }, 317 | { 318 | "cell_type": "code", 319 | "execution_count": 16, 320 | "id": "1492ceb7", 321 | "metadata": {}, 322 | "outputs": [ 323 | { 324 | "name": "stdout", 325 | "output_type": "stream", 326 | "text": [ 327 | "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 " 328 | ] 329 | } 330 | ], 331 | "source": [ 332 | "for x in range(1,101):\n", 333 | " print(x,end =' ')" 334 | ] 335 | }, 336 | { 337 | "cell_type": "code", 338 | "execution_count": 17, 339 | "id": "5a769db2", 340 | "metadata": {}, 341 | "outputs": [ 342 | { 343 | "name": "stdout", 344 | "output_type": "stream", 345 | "text": [ 346 | "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 " 347 | ] 348 | } 349 | ], 350 | "source": [ 351 | "for x in range(1,101,2):\n", 352 | " print(x,end =' ')" 353 | ] 354 | }, 355 | { 356 | "cell_type": "code", 357 | "execution_count": 18, 358 | "id": "a4335d9e", 359 | "metadata": {}, 360 | "outputs": [ 361 | { 362 | "name": "stdout", 363 | "output_type": "stream", 364 | "text": [ 365 | "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 " 366 | ] 367 | } 368 | ], 369 | "source": [ 370 | "for x in range(2,101,2):\n", 371 | " print(x,end =' ')" 372 | ] 373 | }, 374 | { 375 | "cell_type": "markdown", 376 | "id": "3ddcfa6e", 377 | "metadata": {}, 378 | "source": [ 379 | "# LOOPS" 380 | ] 381 | }, 382 | { 383 | "cell_type": "code", 384 | "execution_count": 19, 385 | "id": "c12a1d17", 386 | "metadata": {}, 387 | "outputs": [ 388 | { 389 | "data": { 390 | "text/plain": [ 391 | "'\\nwhile \\nfor \\n'" 392 | ] 393 | }, 394 | "execution_count": 19, 395 | "metadata": {}, 396 | "output_type": "execute_result" 397 | } 398 | ], 399 | "source": [ 400 | "'''\n", 401 | "while \n", 402 | "for \n", 403 | "'''" 404 | ] 405 | }, 406 | { 407 | "cell_type": "code", 408 | "execution_count": 21, 409 | "id": "83c2510d", 410 | "metadata": {}, 411 | "outputs": [ 412 | { 413 | "name": "stdout", 414 | "output_type": "stream", 415 | "text": [ 416 | "1\n", 417 | "2\n", 418 | "3\n", 419 | "4\n", 420 | "5\n", 421 | "6\n", 422 | "7\n", 423 | "8\n", 424 | "9\n", 425 | "10\n", 426 | "The value of the x is : 11\n" 427 | ] 428 | } 429 | ], 430 | "source": [ 431 | "# while :\n", 432 | "# statements\n", 433 | "\n", 434 | "x=1\n", 435 | "\n", 436 | "while x<=10:\n", 437 | " print(x)\n", 438 | " x=x+1\n", 439 | "else:\n", 440 | " print(\"The value of the x is :\",x)" 441 | ] 442 | }, 443 | { 444 | "cell_type": "code", 445 | "execution_count": 22, 446 | "id": "5b6a9aeb", 447 | "metadata": {}, 448 | "outputs": [], 449 | "source": [ 450 | "info=['ExcelR','Data Analytics','Python',2022,100] " 451 | ] 452 | }, 453 | { 454 | "cell_type": "code", 455 | "execution_count": 23, 456 | "id": "903c35d9", 457 | "metadata": {}, 458 | "outputs": [ 459 | { 460 | "name": "stdout", 461 | "output_type": "stream", 462 | "text": [ 463 | "ExcelR\n", 464 | "Data Analytics\n", 465 | "Python\n", 466 | "2022\n", 467 | "100\n" 468 | ] 469 | } 470 | ], 471 | "source": [ 472 | "for x in info:\n", 473 | " print(x)" 474 | ] 475 | }, 476 | { 477 | "cell_type": "code", 478 | "execution_count": 39, 479 | "id": "9dc87558", 480 | "metadata": {}, 481 | "outputs": [ 482 | { 483 | "name": "stdout", 484 | "output_type": "stream", 485 | "text": [ 486 | "1 2 3 4 5 6 7 8 9 10 \n", 487 | " 11 12 13 14 15 16 17 18 19 20 21 \n", 488 | " 22 23 24 25 26 27 28 29 30 31 32 \n", 489 | " 33 34 35 36 37 38 39 40 41 42 43 \n", 490 | " 44 45 46 47 48 49 50 51 52 53 54 \n", 491 | " 55 56 57 58 59 60 61 62 63 64 65 \n", 492 | " 66 67 68 69 70 71 72 73 74 75 76 \n", 493 | " 77 78 79 80 81 82 83 84 85 86 87 \n", 494 | " 88 89 90 91 92 93 94 95 96 97 98 \n", 495 | " 99 100 " 496 | ] 497 | } 498 | ], 499 | "source": [ 500 | "i=1\n", 501 | "for x in range(1,101):\n", 502 | " if i<=10:\n", 503 | " print(x, end=' ')\n", 504 | " i=i+1 \n", 505 | " else:\n", 506 | " print('\\n',x, end=' ')\n", 507 | " i=1\n" 508 | ] 509 | }, 510 | { 511 | "cell_type": "markdown", 512 | "id": "07e9fe5f", 513 | "metadata": {}, 514 | "source": [ 515 | "# Flow control statements" 516 | ] 517 | }, 518 | { 519 | "cell_type": "code", 520 | "execution_count": null, 521 | "id": "76b9e1c9", 522 | "metadata": {}, 523 | "outputs": [], 524 | "source": [ 525 | "'''\n", 526 | "break\n", 527 | "continue\n", 528 | "'''" 529 | ] 530 | }, 531 | { 532 | "cell_type": "code", 533 | "execution_count": 41, 534 | "id": "48ebccb9", 535 | "metadata": {}, 536 | "outputs": [ 537 | { 538 | "name": "stdout", 539 | "output_type": "stream", 540 | "text": [ 541 | "1\n", 542 | "2\n", 543 | "3\n", 544 | "4\n", 545 | "This is the next line to the loop\n", 546 | "Thanks\n" 547 | ] 548 | } 549 | ], 550 | "source": [ 551 | "x=1\n", 552 | "\n", 553 | "while x<=10:\n", 554 | " if x==5:\n", 555 | " break\n", 556 | " print(x)\n", 557 | " x=x+1\n", 558 | " \n", 559 | "print(\"This is the next line to the loop\")\n", 560 | "print(\"Thanks\")" 561 | ] 562 | }, 563 | { 564 | "cell_type": "code", 565 | "execution_count": 42, 566 | "id": "335f8082", 567 | "metadata": {}, 568 | "outputs": [ 569 | { 570 | "name": "stdout", 571 | "output_type": "stream", 572 | "text": [ 573 | "1\n", 574 | "2\n", 575 | "3\n", 576 | "4\n", 577 | "6\n", 578 | "7\n", 579 | "8\n", 580 | "9\n", 581 | "10\n", 582 | "11\n", 583 | "This is the next line to the loop\n", 584 | "Thanks\n" 585 | ] 586 | } 587 | ], 588 | "source": [ 589 | "x=0\n", 590 | "\n", 591 | "while x<=10:\n", 592 | " x=x+1\n", 593 | " if x==5:\n", 594 | " continue\n", 595 | " print(x)\n", 596 | " \n", 597 | " \n", 598 | "print(\"This is the next line to the loop\")\n", 599 | "print(\"Thanks\")" 600 | ] 601 | }, 602 | { 603 | "cell_type": "markdown", 604 | "id": "3966963b", 605 | "metadata": {}, 606 | "source": [ 607 | "# DATA STRUCTURE" 608 | ] 609 | }, 610 | { 611 | "cell_type": "code", 612 | "execution_count": null, 613 | "id": "f3bfa742", 614 | "metadata": {}, 615 | "outputs": [], 616 | "source": [ 617 | "'''\n", 618 | "Immutable\n", 619 | " - Numbers\n", 620 | " - String\n", 621 | " - Tuple\n", 622 | "Mutable\n", 623 | " - List\n", 624 | " - Dictionary\n", 625 | " - Set\n", 626 | "'''" 627 | ] 628 | }, 629 | { 630 | "cell_type": "code", 631 | "execution_count": 43, 632 | "id": "9000b335", 633 | "metadata": {}, 634 | "outputs": [ 635 | { 636 | "ename": "SyntaxError", 637 | "evalue": "cannot assign to literal (2169748992.py, line 1)", 638 | "output_type": "error", 639 | "traceback": [ 640 | "\u001b[1;36m Input \u001b[1;32mIn [43]\u001b[1;36m\u001b[0m\n\u001b[1;33m 5=7\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m cannot assign to literal\n" 641 | ] 642 | } 643 | ], 644 | "source": [ 645 | "'''\n", 646 | "Arithmetic Opearators\n", 647 | "Assignment\n", 648 | "Comparison\n", 649 | "Bitwise\n", 650 | "Binary\n", 651 | "Identity \n", 652 | "Membership\n", 653 | "'''" 654 | ] 655 | }, 656 | { 657 | "cell_type": "code", 658 | "execution_count": 44, 659 | "id": "00440d85", 660 | "metadata": {}, 661 | "outputs": [ 662 | { 663 | "data": { 664 | "text/plain": [ 665 | "11" 666 | ] 667 | }, 668 | "execution_count": 44, 669 | "metadata": {}, 670 | "output_type": "execute_result" 671 | } 672 | ], 673 | "source": [ 674 | "# + (Addtion), -(subraction), * (multiplication), / (division), ** ( Exponent), % (modulus) , // (Floor Division)\n", 675 | "\n", 676 | "5+6" 677 | ] 678 | }, 679 | { 680 | "cell_type": "code", 681 | "execution_count": 45, 682 | "id": "a309c8d4", 683 | "metadata": {}, 684 | "outputs": [ 685 | { 686 | "data": { 687 | "text/plain": [ 688 | "-1" 689 | ] 690 | }, 691 | "execution_count": 45, 692 | "metadata": {}, 693 | "output_type": "execute_result" 694 | } 695 | ], 696 | "source": [ 697 | "5-6" 698 | ] 699 | }, 700 | { 701 | "cell_type": "code", 702 | "execution_count": 46, 703 | "id": "aa70cfb5", 704 | "metadata": {}, 705 | "outputs": [ 706 | { 707 | "data": { 708 | "text/plain": [ 709 | "30" 710 | ] 711 | }, 712 | "execution_count": 46, 713 | "metadata": {}, 714 | "output_type": "execute_result" 715 | } 716 | ], 717 | "source": [ 718 | "5*6" 719 | ] 720 | }, 721 | { 722 | "cell_type": "code", 723 | "execution_count": 47, 724 | "id": "056eac97", 725 | "metadata": {}, 726 | "outputs": [ 727 | { 728 | "data": { 729 | "text/plain": [ 730 | "0.8333333333333334" 731 | ] 732 | }, 733 | "execution_count": 47, 734 | "metadata": {}, 735 | "output_type": "execute_result" 736 | } 737 | ], 738 | "source": [ 739 | "5/6" 740 | ] 741 | }, 742 | { 743 | "cell_type": "code", 744 | "execution_count": 48, 745 | "id": "eb3971c7", 746 | "metadata": {}, 747 | "outputs": [ 748 | { 749 | "data": { 750 | "text/plain": [ 751 | "8" 752 | ] 753 | }, 754 | "execution_count": 48, 755 | "metadata": {}, 756 | "output_type": "execute_result" 757 | } 758 | ], 759 | "source": [ 760 | "2**3" 761 | ] 762 | }, 763 | { 764 | "cell_type": "code", 765 | "execution_count": 49, 766 | "id": "d25a8387", 767 | "metadata": {}, 768 | "outputs": [ 769 | { 770 | "data": { 771 | "text/plain": [ 772 | "1" 773 | ] 774 | }, 775 | "execution_count": 49, 776 | "metadata": {}, 777 | "output_type": "execute_result" 778 | } 779 | ], 780 | "source": [ 781 | "11%2 # Return the reminder" 782 | ] 783 | }, 784 | { 785 | "cell_type": "code", 786 | "execution_count": 50, 787 | "id": "cf1dda42", 788 | "metadata": {}, 789 | "outputs": [ 790 | { 791 | "data": { 792 | "text/plain": [ 793 | "5" 794 | ] 795 | }, 796 | "execution_count": 50, 797 | "metadata": {}, 798 | "output_type": "execute_result" 799 | } 800 | ], 801 | "source": [ 802 | "11//2 " 803 | ] 804 | }, 805 | { 806 | "cell_type": "code", 807 | "execution_count": 52, 808 | "id": "f90e83d0", 809 | "metadata": {}, 810 | "outputs": [], 811 | "source": [ 812 | "# Assignment\n", 813 | "\n", 814 | "x=10" 815 | ] 816 | }, 817 | { 818 | "cell_type": "code", 819 | "execution_count": 53, 820 | "id": "64cf68e9", 821 | "metadata": {}, 822 | "outputs": [ 823 | { 824 | "data": { 825 | "text/plain": [ 826 | "10" 827 | ] 828 | }, 829 | "execution_count": 53, 830 | "metadata": {}, 831 | "output_type": "execute_result" 832 | } 833 | ], 834 | "source": [ 835 | "x" 836 | ] 837 | }, 838 | { 839 | "cell_type": "code", 840 | "execution_count": 54, 841 | "id": "f16ae03a", 842 | "metadata": {}, 843 | "outputs": [], 844 | "source": [ 845 | "y=x" 846 | ] 847 | }, 848 | { 849 | "cell_type": "code", 850 | "execution_count": 55, 851 | "id": "5506c05b", 852 | "metadata": {}, 853 | "outputs": [ 854 | { 855 | "data": { 856 | "text/plain": [ 857 | "10" 858 | ] 859 | }, 860 | "execution_count": 55, 861 | "metadata": {}, 862 | "output_type": "execute_result" 863 | } 864 | ], 865 | "source": [ 866 | "y" 867 | ] 868 | }, 869 | { 870 | "cell_type": "code", 871 | "execution_count": 56, 872 | "id": "89dd3ec8", 873 | "metadata": {}, 874 | "outputs": [], 875 | "source": [ 876 | "z=x*2" 877 | ] 878 | }, 879 | { 880 | "cell_type": "code", 881 | "execution_count": 57, 882 | "id": "9ac9212d", 883 | "metadata": {}, 884 | "outputs": [ 885 | { 886 | "data": { 887 | "text/plain": [ 888 | "20" 889 | ] 890 | }, 891 | "execution_count": 57, 892 | "metadata": {}, 893 | "output_type": "execute_result" 894 | } 895 | ], 896 | "source": [ 897 | "z" 898 | ] 899 | }, 900 | { 901 | "cell_type": "code", 902 | "execution_count": 61, 903 | "id": "dce7f310", 904 | "metadata": {}, 905 | "outputs": [], 906 | "source": [ 907 | "res=x+y+z" 908 | ] 909 | }, 910 | { 911 | "cell_type": "code", 912 | "execution_count": 62, 913 | "id": "b620f33d", 914 | "metadata": {}, 915 | "outputs": [ 916 | { 917 | "data": { 918 | "text/plain": [ 919 | "40" 920 | ] 921 | }, 922 | "execution_count": 62, 923 | "metadata": {}, 924 | "output_type": "execute_result" 925 | } 926 | ], 927 | "source": [ 928 | "res" 929 | ] 930 | }, 931 | { 932 | "cell_type": "code", 933 | "execution_count": 63, 934 | "id": "b3c28953", 935 | "metadata": {}, 936 | "outputs": [ 937 | { 938 | "data": { 939 | "text/plain": [ 940 | "10" 941 | ] 942 | }, 943 | "execution_count": 63, 944 | "metadata": {}, 945 | "output_type": "execute_result" 946 | } 947 | ], 948 | "source": [ 949 | "#Comparison\n", 950 | "\n", 951 | "x" 952 | ] 953 | }, 954 | { 955 | "cell_type": "code", 956 | "execution_count": 64, 957 | "id": "14ede553", 958 | "metadata": {}, 959 | "outputs": [ 960 | { 961 | "data": { 962 | "text/plain": [ 963 | "True" 964 | ] 965 | }, 966 | "execution_count": 64, 967 | "metadata": {}, 968 | "output_type": "execute_result" 969 | } 970 | ], 971 | "source": [ 972 | "x==10" 973 | ] 974 | }, 975 | { 976 | "cell_type": "code", 977 | "execution_count": 65, 978 | "id": "1628201f", 979 | "metadata": {}, 980 | "outputs": [ 981 | { 982 | "data": { 983 | "text/plain": [ 984 | "True" 985 | ] 986 | }, 987 | "execution_count": 65, 988 | "metadata": {}, 989 | "output_type": "execute_result" 990 | } 991 | ], 992 | "source": [ 993 | "x>0" 994 | ] 995 | }, 996 | { 997 | "cell_type": "code", 998 | "execution_count": 66, 999 | "id": "85ba09db", 1000 | "metadata": {}, 1001 | "outputs": [ 1002 | { 1003 | "data": { 1004 | "text/plain": [ 1005 | "False" 1006 | ] 1007 | }, 1008 | "execution_count": 66, 1009 | "metadata": {}, 1010 | "output_type": "execute_result" 1011 | } 1012 | ], 1013 | "source": [ 1014 | "x>100" 1015 | ] 1016 | }, 1017 | { 1018 | "cell_type": "code", 1019 | "execution_count": 67, 1020 | "id": "d180e87d", 1021 | "metadata": {}, 1022 | "outputs": [ 1023 | { 1024 | "data": { 1025 | "text/plain": [ 1026 | "False" 1027 | ] 1028 | }, 1029 | "execution_count": 67, 1030 | "metadata": {}, 1031 | "output_type": "execute_result" 1032 | } 1033 | ], 1034 | "source": [ 1035 | "x==0" 1036 | ] 1037 | }, 1038 | { 1039 | "cell_type": "code", 1040 | "execution_count": 68, 1041 | "id": "317c8603", 1042 | "metadata": {}, 1043 | "outputs": [ 1044 | { 1045 | "data": { 1046 | "text/plain": [ 1047 | "True" 1048 | ] 1049 | }, 1050 | "execution_count": 68, 1051 | "metadata": {}, 1052 | "output_type": "execute_result" 1053 | } 1054 | ], 1055 | "source": [ 1056 | "x != 0" 1057 | ] 1058 | }, 1059 | { 1060 | "cell_type": "code", 1061 | "execution_count": null, 1062 | "id": "7598748c", 1063 | "metadata": {}, 1064 | "outputs": [], 1065 | "source": [] 1066 | } 1067 | ], 1068 | "metadata": { 1069 | "kernelspec": { 1070 | "display_name": "Python 3 (ipykernel)", 1071 | "language": "python", 1072 | "name": "python3" 1073 | }, 1074 | "language_info": { 1075 | "codemirror_mode": { 1076 | "name": "ipython", 1077 | "version": 3 1078 | }, 1079 | "file_extension": ".py", 1080 | "mimetype": "text/x-python", 1081 | "name": "python", 1082 | "nbconvert_exporter": "python", 1083 | "pygments_lexer": "ipython3", 1084 | "version": "3.8.10" 1085 | } 1086 | }, 1087 | "nbformat": 4, 1088 | "nbformat_minor": 5 1089 | } 1090 | -------------------------------------------------------------------------------- /Loops-DataStructure_2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "f1b4eb44", 6 | "metadata": {}, 7 | "source": [ 8 | "# print functions" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "id": "3c223db5", 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "Hello\n" 22 | ] 23 | } 24 | ], 25 | "source": [ 26 | "print(\"Hello\")" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": 2, 32 | "id": "1783bebb", 33 | "metadata": {}, 34 | "outputs": [], 35 | "source": [ 36 | "name='Raghul Ramesh'" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 3, 42 | "id": "6b014959", 43 | "metadata": {}, 44 | "outputs": [ 45 | { 46 | "name": "stdout", 47 | "output_type": "stream", 48 | "text": [ 49 | "name\n" 50 | ] 51 | } 52 | ], 53 | "source": [ 54 | "print('name')" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": 4, 60 | "id": "e0cbe74e", 61 | "metadata": {}, 62 | "outputs": [ 63 | { 64 | "name": "stdout", 65 | "output_type": "stream", 66 | "text": [ 67 | "Raghul Ramesh\n" 68 | ] 69 | } 70 | ], 71 | "source": [ 72 | "print(name)" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": 5, 78 | "id": "6aae1fb2", 79 | "metadata": {}, 80 | "outputs": [ 81 | { 82 | "name": "stdout", 83 | "output_type": "stream", 84 | "text": [ 85 | "Trainer name is : name\n" 86 | ] 87 | } 88 | ], 89 | "source": [ 90 | "print('Trainer name is : name')" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 6, 96 | "id": "b106b3c9", 97 | "metadata": {}, 98 | "outputs": [ 99 | { 100 | "name": "stdout", 101 | "output_type": "stream", 102 | "text": [ 103 | "Trainer name is : Raghul Ramesh\n" 104 | ] 105 | } 106 | ], 107 | "source": [ 108 | "print('Trainer name is : ',name)" 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": 7, 114 | "id": "f1c0ab02", 115 | "metadata": {}, 116 | "outputs": [ 117 | { 118 | "name": "stdout", 119 | "output_type": "stream", 120 | "text": [ 121 | "Trainer name is Raghul Ramesh and he is 37 years old\n" 122 | ] 123 | } 124 | ], 125 | "source": [ 126 | "name='Raghul Ramesh'\n", 127 | "age=37\n", 128 | "city='Chennai'\n", 129 | "\n", 130 | "#Trainer name is Raghul Ramesh and he is 37 years old\n", 131 | "\n", 132 | "print(\"Trainer name is \", name , \"and he is \", age , \"years old\")" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": 8, 138 | "id": "1af88384", 139 | "metadata": {}, 140 | "outputs": [ 141 | { 142 | "name": "stdout", 143 | "output_type": "stream", 144 | "text": [ 145 | "Trainer name is Raghul Ramesh and he is 37 years old and he is from Chennai\n" 146 | ] 147 | } 148 | ], 149 | "source": [ 150 | "print(\"Trainer name is {} and he is {} years old and he is from {}\".format(name,age,city))" 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "execution_count": 9, 156 | "id": "c641c93e", 157 | "metadata": {}, 158 | "outputs": [ 159 | { 160 | "name": "stdout", 161 | "output_type": "stream", 162 | "text": [ 163 | "Trainer name is Raghul Ramesh and he is 37 years old and he is from Chennai\n" 164 | ] 165 | } 166 | ], 167 | "source": [ 168 | "print(f\"Trainer name is {name} and he is {age} years old and he is from {city}\")" 169 | ] 170 | }, 171 | { 172 | "cell_type": "code", 173 | "execution_count": 10, 174 | "id": "4d4081a1", 175 | "metadata": {}, 176 | "outputs": [ 177 | { 178 | "name": "stdout", 179 | "output_type": "stream", 180 | "text": [ 181 | "Trainer name is Raghul Ramesh and he is 37 years old and he is from Chennai\n" 182 | ] 183 | } 184 | ], 185 | "source": [ 186 | "print(\"Trainer name is {2} and he is {0} years old and he is from {1}\".format(age,city,name))" 187 | ] 188 | }, 189 | { 190 | "cell_type": "code", 191 | "execution_count": 11, 192 | "id": "26e32bcc", 193 | "metadata": {}, 194 | "outputs": [ 195 | { 196 | "name": "stdout", 197 | "output_type": "stream", 198 | "text": [ 199 | "The product's price is : 565.659\n" 200 | ] 201 | } 202 | ], 203 | "source": [ 204 | "price=565.6587432\n", 205 | "print(\"The product's price is : {0:.3f}\".format(price))" 206 | ] 207 | }, 208 | { 209 | "cell_type": "code", 210 | "execution_count": 12, 211 | "id": "595d116f", 212 | "metadata": {}, 213 | "outputs": [ 214 | { 215 | "data": { 216 | "text/plain": [ 217 | "565.659" 218 | ] 219 | }, 220 | "execution_count": 12, 221 | "metadata": {}, 222 | "output_type": "execute_result" 223 | } 224 | ], 225 | "source": [ 226 | "round(price,3)" 227 | ] 228 | }, 229 | { 230 | "cell_type": "code", 231 | "execution_count": 13, 232 | "id": "8fdc0bc5", 233 | "metadata": {}, 234 | "outputs": [ 235 | { 236 | "name": "stdout", 237 | "output_type": "stream", 238 | "text": [ 239 | "The product's price is : 565.66\n" 240 | ] 241 | } 242 | ], 243 | "source": [ 244 | "print(\"The product's price is : {}\".format(round(price,2)))" 245 | ] 246 | }, 247 | { 248 | "cell_type": "markdown", 249 | "id": "3520948a", 250 | "metadata": {}, 251 | "source": [ 252 | "# input function" 253 | ] 254 | }, 255 | { 256 | "cell_type": "code", 257 | "execution_count": 14, 258 | "id": "b561f492", 259 | "metadata": {}, 260 | "outputs": [ 261 | { 262 | "name": "stdout", 263 | "output_type": "stream", 264 | "text": [ 265 | "Enter your name:Raghul Ramesh\n", 266 | "Enter your age:37\n", 267 | "The type of name is : \n", 268 | "The type of age is : \n", 269 | "Age is: 38\n" 270 | ] 271 | } 272 | ], 273 | "source": [ 274 | "name=input(\"Enter your name:\")\n", 275 | "age=int(input(\"Enter your age:\"))\n", 276 | "age=age+1\n", 277 | "print(\"The type of name is :\", type(name))\n", 278 | "print(\"The type of age is :\", type(age))\n", 279 | "print(\"Age is:\",age)" 280 | ] 281 | }, 282 | { 283 | "cell_type": "code", 284 | "execution_count": 15, 285 | "id": "b63b0bb8", 286 | "metadata": {}, 287 | "outputs": [ 288 | { 289 | "name": "stdout", 290 | "output_type": "stream", 291 | "text": [ 292 | "Enter your account number:43728734432\n", 293 | "Enter your name:Raghul Ramesh\n", 294 | "Enter 4 digit pin:44542\n", 295 | "43728734432,Raghul Ramesh,44542\n", 296 | "Type of acct:, name: and pin:\n" 297 | ] 298 | } 299 | ], 300 | "source": [ 301 | "acct=input(\"Enter your account number:\")\n", 302 | "name=input(\"Enter your name:\")\n", 303 | "pin=int(input(\"Enter 4 digit pin:\"))\n", 304 | "\n", 305 | "print(\"{},{},{}\".format(acct,name,pin))\n", 306 | "print(\"Type of acct:{}, name:{} and pin:{}\".format(type(acct),type(name),type(pin)))" 307 | ] 308 | }, 309 | { 310 | "cell_type": "markdown", 311 | "id": "07c2de6d", 312 | "metadata": {}, 313 | "source": [ 314 | "# range function" 315 | ] 316 | }, 317 | { 318 | "cell_type": "code", 319 | "execution_count": 16, 320 | "id": "1492ceb7", 321 | "metadata": {}, 322 | "outputs": [ 323 | { 324 | "name": "stdout", 325 | "output_type": "stream", 326 | "text": [ 327 | "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 " 328 | ] 329 | } 330 | ], 331 | "source": [ 332 | "for x in range(1,101):\n", 333 | " print(x,end =' ')" 334 | ] 335 | }, 336 | { 337 | "cell_type": "code", 338 | "execution_count": 17, 339 | "id": "5a769db2", 340 | "metadata": {}, 341 | "outputs": [ 342 | { 343 | "name": "stdout", 344 | "output_type": "stream", 345 | "text": [ 346 | "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 " 347 | ] 348 | } 349 | ], 350 | "source": [ 351 | "for x in range(1,101,2):\n", 352 | " print(x,end =' ')" 353 | ] 354 | }, 355 | { 356 | "cell_type": "code", 357 | "execution_count": 18, 358 | "id": "a4335d9e", 359 | "metadata": {}, 360 | "outputs": [ 361 | { 362 | "name": "stdout", 363 | "output_type": "stream", 364 | "text": [ 365 | "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 " 366 | ] 367 | } 368 | ], 369 | "source": [ 370 | "for x in range(2,101,2):\n", 371 | " print(x,end =' ')" 372 | ] 373 | }, 374 | { 375 | "cell_type": "markdown", 376 | "id": "3ddcfa6e", 377 | "metadata": {}, 378 | "source": [ 379 | "# LOOPS" 380 | ] 381 | }, 382 | { 383 | "cell_type": "code", 384 | "execution_count": 19, 385 | "id": "c12a1d17", 386 | "metadata": {}, 387 | "outputs": [ 388 | { 389 | "data": { 390 | "text/plain": [ 391 | "'\\nwhile \\nfor \\n'" 392 | ] 393 | }, 394 | "execution_count": 19, 395 | "metadata": {}, 396 | "output_type": "execute_result" 397 | } 398 | ], 399 | "source": [ 400 | "'''\n", 401 | "while \n", 402 | "for \n", 403 | "'''" 404 | ] 405 | }, 406 | { 407 | "cell_type": "code", 408 | "execution_count": 21, 409 | "id": "83c2510d", 410 | "metadata": {}, 411 | "outputs": [ 412 | { 413 | "name": "stdout", 414 | "output_type": "stream", 415 | "text": [ 416 | "1\n", 417 | "2\n", 418 | "3\n", 419 | "4\n", 420 | "5\n", 421 | "6\n", 422 | "7\n", 423 | "8\n", 424 | "9\n", 425 | "10\n", 426 | "The value of the x is : 11\n" 427 | ] 428 | } 429 | ], 430 | "source": [ 431 | "# while :\n", 432 | "# statements\n", 433 | "\n", 434 | "x=1\n", 435 | "\n", 436 | "while x<=10:\n", 437 | " print(x)\n", 438 | " x=x+1\n", 439 | "else:\n", 440 | " print(\"The value of the x is :\",x)" 441 | ] 442 | }, 443 | { 444 | "cell_type": "code", 445 | "execution_count": 22, 446 | "id": "5b6a9aeb", 447 | "metadata": {}, 448 | "outputs": [], 449 | "source": [ 450 | "info=['ExcelR','Data Analytics','Python',2022,100] " 451 | ] 452 | }, 453 | { 454 | "cell_type": "code", 455 | "execution_count": 23, 456 | "id": "903c35d9", 457 | "metadata": {}, 458 | "outputs": [ 459 | { 460 | "name": "stdout", 461 | "output_type": "stream", 462 | "text": [ 463 | "ExcelR\n", 464 | "Data Analytics\n", 465 | "Python\n", 466 | "2022\n", 467 | "100\n" 468 | ] 469 | } 470 | ], 471 | "source": [ 472 | "for x in info:\n", 473 | " print(x)" 474 | ] 475 | }, 476 | { 477 | "cell_type": "code", 478 | "execution_count": 39, 479 | "id": "9dc87558", 480 | "metadata": {}, 481 | "outputs": [ 482 | { 483 | "name": "stdout", 484 | "output_type": "stream", 485 | "text": [ 486 | "1 2 3 4 5 6 7 8 9 10 \n", 487 | " 11 12 13 14 15 16 17 18 19 20 21 \n", 488 | " 22 23 24 25 26 27 28 29 30 31 32 \n", 489 | " 33 34 35 36 37 38 39 40 41 42 43 \n", 490 | " 44 45 46 47 48 49 50 51 52 53 54 \n", 491 | " 55 56 57 58 59 60 61 62 63 64 65 \n", 492 | " 66 67 68 69 70 71 72 73 74 75 76 \n", 493 | " 77 78 79 80 81 82 83 84 85 86 87 \n", 494 | " 88 89 90 91 92 93 94 95 96 97 98 \n", 495 | " 99 100 " 496 | ] 497 | } 498 | ], 499 | "source": [ 500 | "i=1\n", 501 | "for x in range(1,101):\n", 502 | " if i<=10:\n", 503 | " print(x, end=' ')\n", 504 | " i=i+1 \n", 505 | " else:\n", 506 | " print('\\n',x, end=' ')\n", 507 | " i=1\n" 508 | ] 509 | }, 510 | { 511 | "cell_type": "markdown", 512 | "id": "07e9fe5f", 513 | "metadata": {}, 514 | "source": [ 515 | "# Flow control statements" 516 | ] 517 | }, 518 | { 519 | "cell_type": "code", 520 | "execution_count": null, 521 | "id": "76b9e1c9", 522 | "metadata": {}, 523 | "outputs": [], 524 | "source": [ 525 | "'''\n", 526 | "break\n", 527 | "continue\n", 528 | "'''" 529 | ] 530 | }, 531 | { 532 | "cell_type": "code", 533 | "execution_count": 41, 534 | "id": "48ebccb9", 535 | "metadata": {}, 536 | "outputs": [ 537 | { 538 | "name": "stdout", 539 | "output_type": "stream", 540 | "text": [ 541 | "1\n", 542 | "2\n", 543 | "3\n", 544 | "4\n", 545 | "This is the next line to the loop\n", 546 | "Thanks\n" 547 | ] 548 | } 549 | ], 550 | "source": [ 551 | "x=1\n", 552 | "\n", 553 | "while x<=10:\n", 554 | " if x==5:\n", 555 | " break\n", 556 | " print(x)\n", 557 | " x=x+1\n", 558 | " \n", 559 | "print(\"This is the next line to the loop\")\n", 560 | "print(\"Thanks\")" 561 | ] 562 | }, 563 | { 564 | "cell_type": "code", 565 | "execution_count": 42, 566 | "id": "335f8082", 567 | "metadata": {}, 568 | "outputs": [ 569 | { 570 | "name": "stdout", 571 | "output_type": "stream", 572 | "text": [ 573 | "1\n", 574 | "2\n", 575 | "3\n", 576 | "4\n", 577 | "6\n", 578 | "7\n", 579 | "8\n", 580 | "9\n", 581 | "10\n", 582 | "11\n", 583 | "This is the next line to the loop\n", 584 | "Thanks\n" 585 | ] 586 | } 587 | ], 588 | "source": [ 589 | "x=0\n", 590 | "\n", 591 | "while x<=10:\n", 592 | " x=x+1\n", 593 | " if x==5:\n", 594 | " continue\n", 595 | " print(x)\n", 596 | " \n", 597 | " \n", 598 | "print(\"This is the next line to the loop\")\n", 599 | "print(\"Thanks\")" 600 | ] 601 | }, 602 | { 603 | "cell_type": "markdown", 604 | "id": "3966963b", 605 | "metadata": {}, 606 | "source": [ 607 | "# DATA STRUCTURE" 608 | ] 609 | }, 610 | { 611 | "cell_type": "code", 612 | "execution_count": null, 613 | "id": "f3bfa742", 614 | "metadata": {}, 615 | "outputs": [], 616 | "source": [ 617 | "'''\n", 618 | "Immutable\n", 619 | " - Numbers\n", 620 | " - String\n", 621 | " - Tuple\n", 622 | "Mutable\n", 623 | " - List\n", 624 | " - Dictionary\n", 625 | " - Set\n", 626 | "'''" 627 | ] 628 | }, 629 | { 630 | "cell_type": "code", 631 | "execution_count": 43, 632 | "id": "9000b335", 633 | "metadata": {}, 634 | "outputs": [ 635 | { 636 | "ename": "SyntaxError", 637 | "evalue": "cannot assign to literal (2169748992.py, line 1)", 638 | "output_type": "error", 639 | "traceback": [ 640 | "\u001b[1;36m Input \u001b[1;32mIn [43]\u001b[1;36m\u001b[0m\n\u001b[1;33m 5=7\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m cannot assign to literal\n" 641 | ] 642 | } 643 | ], 644 | "source": [ 645 | "'''\n", 646 | "Arithmetic Opearators\n", 647 | "Assignment\n", 648 | "Comparison\n", 649 | "Bitwise\n", 650 | "Binary\n", 651 | "Identity \n", 652 | "Membership\n", 653 | "'''" 654 | ] 655 | }, 656 | { 657 | "cell_type": "code", 658 | "execution_count": 44, 659 | "id": "00440d85", 660 | "metadata": {}, 661 | "outputs": [ 662 | { 663 | "data": { 664 | "text/plain": [ 665 | "11" 666 | ] 667 | }, 668 | "execution_count": 44, 669 | "metadata": {}, 670 | "output_type": "execute_result" 671 | } 672 | ], 673 | "source": [ 674 | "# + (Addtion), -(subraction), * (multiplication), / (division), ** ( Exponent), % (modulus) , // (Floor Division)\n", 675 | "\n", 676 | "5+6" 677 | ] 678 | }, 679 | { 680 | "cell_type": "code", 681 | "execution_count": 45, 682 | "id": "a309c8d4", 683 | "metadata": {}, 684 | "outputs": [ 685 | { 686 | "data": { 687 | "text/plain": [ 688 | "-1" 689 | ] 690 | }, 691 | "execution_count": 45, 692 | "metadata": {}, 693 | "output_type": "execute_result" 694 | } 695 | ], 696 | "source": [ 697 | "5-6" 698 | ] 699 | }, 700 | { 701 | "cell_type": "code", 702 | "execution_count": 46, 703 | "id": "aa70cfb5", 704 | "metadata": {}, 705 | "outputs": [ 706 | { 707 | "data": { 708 | "text/plain": [ 709 | "30" 710 | ] 711 | }, 712 | "execution_count": 46, 713 | "metadata": {}, 714 | "output_type": "execute_result" 715 | } 716 | ], 717 | "source": [ 718 | "5*6" 719 | ] 720 | }, 721 | { 722 | "cell_type": "code", 723 | "execution_count": 47, 724 | "id": "056eac97", 725 | "metadata": {}, 726 | "outputs": [ 727 | { 728 | "data": { 729 | "text/plain": [ 730 | "0.8333333333333334" 731 | ] 732 | }, 733 | "execution_count": 47, 734 | "metadata": {}, 735 | "output_type": "execute_result" 736 | } 737 | ], 738 | "source": [ 739 | "5/6" 740 | ] 741 | }, 742 | { 743 | "cell_type": "code", 744 | "execution_count": 48, 745 | "id": "eb3971c7", 746 | "metadata": {}, 747 | "outputs": [ 748 | { 749 | "data": { 750 | "text/plain": [ 751 | "8" 752 | ] 753 | }, 754 | "execution_count": 48, 755 | "metadata": {}, 756 | "output_type": "execute_result" 757 | } 758 | ], 759 | "source": [ 760 | "2**3" 761 | ] 762 | }, 763 | { 764 | "cell_type": "code", 765 | "execution_count": 49, 766 | "id": "d25a8387", 767 | "metadata": {}, 768 | "outputs": [ 769 | { 770 | "data": { 771 | "text/plain": [ 772 | "1" 773 | ] 774 | }, 775 | "execution_count": 49, 776 | "metadata": {}, 777 | "output_type": "execute_result" 778 | } 779 | ], 780 | "source": [ 781 | "11%2 # Return the reminder" 782 | ] 783 | }, 784 | { 785 | "cell_type": "code", 786 | "execution_count": 50, 787 | "id": "cf1dda42", 788 | "metadata": {}, 789 | "outputs": [ 790 | { 791 | "data": { 792 | "text/plain": [ 793 | "5" 794 | ] 795 | }, 796 | "execution_count": 50, 797 | "metadata": {}, 798 | "output_type": "execute_result" 799 | } 800 | ], 801 | "source": [ 802 | "11//2 " 803 | ] 804 | }, 805 | { 806 | "cell_type": "code", 807 | "execution_count": 52, 808 | "id": "f90e83d0", 809 | "metadata": {}, 810 | "outputs": [], 811 | "source": [ 812 | "# Assignment\n", 813 | "\n", 814 | "x=10" 815 | ] 816 | }, 817 | { 818 | "cell_type": "code", 819 | "execution_count": 53, 820 | "id": "64cf68e9", 821 | "metadata": {}, 822 | "outputs": [ 823 | { 824 | "data": { 825 | "text/plain": [ 826 | "10" 827 | ] 828 | }, 829 | "execution_count": 53, 830 | "metadata": {}, 831 | "output_type": "execute_result" 832 | } 833 | ], 834 | "source": [ 835 | "x" 836 | ] 837 | }, 838 | { 839 | "cell_type": "code", 840 | "execution_count": 54, 841 | "id": "f16ae03a", 842 | "metadata": {}, 843 | "outputs": [], 844 | "source": [ 845 | "y=x" 846 | ] 847 | }, 848 | { 849 | "cell_type": "code", 850 | "execution_count": 55, 851 | "id": "5506c05b", 852 | "metadata": {}, 853 | "outputs": [ 854 | { 855 | "data": { 856 | "text/plain": [ 857 | "10" 858 | ] 859 | }, 860 | "execution_count": 55, 861 | "metadata": {}, 862 | "output_type": "execute_result" 863 | } 864 | ], 865 | "source": [ 866 | "y" 867 | ] 868 | }, 869 | { 870 | "cell_type": "code", 871 | "execution_count": 56, 872 | "id": "89dd3ec8", 873 | "metadata": {}, 874 | "outputs": [], 875 | "source": [ 876 | "z=x*2" 877 | ] 878 | }, 879 | { 880 | "cell_type": "code", 881 | "execution_count": 57, 882 | "id": "9ac9212d", 883 | "metadata": {}, 884 | "outputs": [ 885 | { 886 | "data": { 887 | "text/plain": [ 888 | "20" 889 | ] 890 | }, 891 | "execution_count": 57, 892 | "metadata": {}, 893 | "output_type": "execute_result" 894 | } 895 | ], 896 | "source": [ 897 | "z" 898 | ] 899 | }, 900 | { 901 | "cell_type": "code", 902 | "execution_count": 61, 903 | "id": "dce7f310", 904 | "metadata": {}, 905 | "outputs": [], 906 | "source": [ 907 | "res=x+y+z" 908 | ] 909 | }, 910 | { 911 | "cell_type": "code", 912 | "execution_count": 62, 913 | "id": "b620f33d", 914 | "metadata": {}, 915 | "outputs": [ 916 | { 917 | "data": { 918 | "text/plain": [ 919 | "40" 920 | ] 921 | }, 922 | "execution_count": 62, 923 | "metadata": {}, 924 | "output_type": "execute_result" 925 | } 926 | ], 927 | "source": [ 928 | "res" 929 | ] 930 | }, 931 | { 932 | "cell_type": "code", 933 | "execution_count": 63, 934 | "id": "b3c28953", 935 | "metadata": {}, 936 | "outputs": [ 937 | { 938 | "data": { 939 | "text/plain": [ 940 | "10" 941 | ] 942 | }, 943 | "execution_count": 63, 944 | "metadata": {}, 945 | "output_type": "execute_result" 946 | } 947 | ], 948 | "source": [ 949 | "#Comparison\n", 950 | "\n", 951 | "x" 952 | ] 953 | }, 954 | { 955 | "cell_type": "code", 956 | "execution_count": 64, 957 | "id": "14ede553", 958 | "metadata": {}, 959 | "outputs": [ 960 | { 961 | "data": { 962 | "text/plain": [ 963 | "True" 964 | ] 965 | }, 966 | "execution_count": 64, 967 | "metadata": {}, 968 | "output_type": "execute_result" 969 | } 970 | ], 971 | "source": [ 972 | "x==10" 973 | ] 974 | }, 975 | { 976 | "cell_type": "code", 977 | "execution_count": 65, 978 | "id": "1628201f", 979 | "metadata": {}, 980 | "outputs": [ 981 | { 982 | "data": { 983 | "text/plain": [ 984 | "True" 985 | ] 986 | }, 987 | "execution_count": 65, 988 | "metadata": {}, 989 | "output_type": "execute_result" 990 | } 991 | ], 992 | "source": [ 993 | "x>0" 994 | ] 995 | }, 996 | { 997 | "cell_type": "code", 998 | "execution_count": 66, 999 | "id": "85ba09db", 1000 | "metadata": {}, 1001 | "outputs": [ 1002 | { 1003 | "data": { 1004 | "text/plain": [ 1005 | "False" 1006 | ] 1007 | }, 1008 | "execution_count": 66, 1009 | "metadata": {}, 1010 | "output_type": "execute_result" 1011 | } 1012 | ], 1013 | "source": [ 1014 | "x>100" 1015 | ] 1016 | }, 1017 | { 1018 | "cell_type": "code", 1019 | "execution_count": 67, 1020 | "id": "d180e87d", 1021 | "metadata": {}, 1022 | "outputs": [ 1023 | { 1024 | "data": { 1025 | "text/plain": [ 1026 | "False" 1027 | ] 1028 | }, 1029 | "execution_count": 67, 1030 | "metadata": {}, 1031 | "output_type": "execute_result" 1032 | } 1033 | ], 1034 | "source": [ 1035 | "x==0" 1036 | ] 1037 | }, 1038 | { 1039 | "cell_type": "code", 1040 | "execution_count": 68, 1041 | "id": "317c8603", 1042 | "metadata": {}, 1043 | "outputs": [ 1044 | { 1045 | "data": { 1046 | "text/plain": [ 1047 | "True" 1048 | ] 1049 | }, 1050 | "execution_count": 68, 1051 | "metadata": {}, 1052 | "output_type": "execute_result" 1053 | } 1054 | ], 1055 | "source": [ 1056 | "x != 0" 1057 | ] 1058 | }, 1059 | { 1060 | "cell_type": "markdown", 1061 | "id": "40147b37", 1062 | "metadata": {}, 1063 | "source": [ 1064 | "# Binary Operators" 1065 | ] 1066 | }, 1067 | { 1068 | "cell_type": "code", 1069 | "execution_count": 2, 1070 | "id": "c0dced37", 1071 | "metadata": {}, 1072 | "outputs": [], 1073 | "source": [ 1074 | "# &(and) |(or) ^(xor)" 1075 | ] 1076 | }, 1077 | { 1078 | "cell_type": "code", 1079 | "execution_count": 3, 1080 | "id": "e53ca621", 1081 | "metadata": {}, 1082 | "outputs": [ 1083 | { 1084 | "data": { 1085 | "text/plain": [ 1086 | "4" 1087 | ] 1088 | }, 1089 | "execution_count": 3, 1090 | "metadata": {}, 1091 | "output_type": "execute_result" 1092 | } 1093 | ], 1094 | "source": [ 1095 | "5&6" 1096 | ] 1097 | }, 1098 | { 1099 | "cell_type": "code", 1100 | "execution_count": 5, 1101 | "id": "d3a271af", 1102 | "metadata": {}, 1103 | "outputs": [ 1104 | { 1105 | "data": { 1106 | "text/plain": [ 1107 | "7" 1108 | ] 1109 | }, 1110 | "execution_count": 5, 1111 | "metadata": {}, 1112 | "output_type": "execute_result" 1113 | } 1114 | ], 1115 | "source": [ 1116 | "5|6" 1117 | ] 1118 | }, 1119 | { 1120 | "cell_type": "code", 1121 | "execution_count": 6, 1122 | "id": "b20c4ec3", 1123 | "metadata": {}, 1124 | "outputs": [ 1125 | { 1126 | "data": { 1127 | "text/plain": [ 1128 | "3" 1129 | ] 1130 | }, 1131 | "execution_count": 6, 1132 | "metadata": {}, 1133 | "output_type": "execute_result" 1134 | } 1135 | ], 1136 | "source": [ 1137 | "5^6" 1138 | ] 1139 | }, 1140 | { 1141 | "cell_type": "markdown", 1142 | "id": "700c79ef", 1143 | "metadata": {}, 1144 | "source": [ 1145 | "# Bitwise Operators" 1146 | ] 1147 | }, 1148 | { 1149 | "cell_type": "code", 1150 | "execution_count": null, 1151 | "id": "ba5edb69", 1152 | "metadata": {}, 1153 | "outputs": [], 1154 | "source": [ 1155 | "#and or not" 1156 | ] 1157 | }, 1158 | { 1159 | "cell_type": "code", 1160 | "execution_count": 7, 1161 | "id": "1ebc7ccb", 1162 | "metadata": {}, 1163 | "outputs": [ 1164 | { 1165 | "data": { 1166 | "text/plain": [ 1167 | "6" 1168 | ] 1169 | }, 1170 | "execution_count": 7, 1171 | "metadata": {}, 1172 | "output_type": "execute_result" 1173 | } 1174 | ], 1175 | "source": [ 1176 | "5 and 6" 1177 | ] 1178 | }, 1179 | { 1180 | "cell_type": "code", 1181 | "execution_count": 8, 1182 | "id": "78b1ba5c", 1183 | "metadata": {}, 1184 | "outputs": [ 1185 | { 1186 | "data": { 1187 | "text/plain": [ 1188 | "5" 1189 | ] 1190 | }, 1191 | "execution_count": 8, 1192 | "metadata": {}, 1193 | "output_type": "execute_result" 1194 | } 1195 | ], 1196 | "source": [ 1197 | "5 or 6" 1198 | ] 1199 | }, 1200 | { 1201 | "cell_type": "code", 1202 | "execution_count": 9, 1203 | "id": "f439b5d2", 1204 | "metadata": {}, 1205 | "outputs": [ 1206 | { 1207 | "data": { 1208 | "text/plain": [ 1209 | "True" 1210 | ] 1211 | }, 1212 | "execution_count": 9, 1213 | "metadata": {}, 1214 | "output_type": "execute_result" 1215 | } 1216 | ], 1217 | "source": [ 1218 | "not 0" 1219 | ] 1220 | }, 1221 | { 1222 | "cell_type": "code", 1223 | "execution_count": 10, 1224 | "id": "c6eae4ad", 1225 | "metadata": {}, 1226 | "outputs": [ 1227 | { 1228 | "data": { 1229 | "text/plain": [ 1230 | "False" 1231 | ] 1232 | }, 1233 | "execution_count": 10, 1234 | "metadata": {}, 1235 | "output_type": "execute_result" 1236 | } 1237 | ], 1238 | "source": [ 1239 | "not 5" 1240 | ] 1241 | }, 1242 | { 1243 | "cell_type": "markdown", 1244 | "id": "0fa11206", 1245 | "metadata": {}, 1246 | "source": [ 1247 | "# Membership" 1248 | ] 1249 | }, 1250 | { 1251 | "cell_type": "code", 1252 | "execution_count": 12, 1253 | "id": "b703cd6b", 1254 | "metadata": {}, 1255 | "outputs": [], 1256 | "source": [ 1257 | "nums=[1,4,7,9,6,4,778,5,443,65,100,3456,67,56,8,5,4,22,43,64,6,3,24,6,7]#" 1258 | ] 1259 | }, 1260 | { 1261 | "cell_type": "code", 1262 | "execution_count": 13, 1263 | "id": "76df3ad2", 1264 | "metadata": {}, 1265 | "outputs": [], 1266 | "source": [ 1267 | "# in , not in " 1268 | ] 1269 | }, 1270 | { 1271 | "cell_type": "code", 1272 | "execution_count": 14, 1273 | "id": "9e739595", 1274 | "metadata": {}, 1275 | "outputs": [ 1276 | { 1277 | "data": { 1278 | "text/plain": [ 1279 | "True" 1280 | ] 1281 | }, 1282 | "execution_count": 14, 1283 | "metadata": {}, 1284 | "output_type": "execute_result" 1285 | } 1286 | ], 1287 | "source": [ 1288 | "5 in nums" 1289 | ] 1290 | }, 1291 | { 1292 | "cell_type": "code", 1293 | "execution_count": 15, 1294 | "id": "95418880", 1295 | "metadata": {}, 1296 | "outputs": [ 1297 | { 1298 | "data": { 1299 | "text/plain": [ 1300 | "False" 1301 | ] 1302 | }, 1303 | "execution_count": 15, 1304 | "metadata": {}, 1305 | "output_type": "execute_result" 1306 | } 1307 | ], 1308 | "source": [ 1309 | "200 in nums" 1310 | ] 1311 | }, 1312 | { 1313 | "cell_type": "code", 1314 | "execution_count": 16, 1315 | "id": "1bdc10a2", 1316 | "metadata": {}, 1317 | "outputs": [ 1318 | { 1319 | "data": { 1320 | "text/plain": [ 1321 | "True" 1322 | ] 1323 | }, 1324 | "execution_count": 16, 1325 | "metadata": {}, 1326 | "output_type": "execute_result" 1327 | } 1328 | ], 1329 | "source": [ 1330 | "200 not in nums" 1331 | ] 1332 | }, 1333 | { 1334 | "cell_type": "markdown", 1335 | "id": "f0aab5b2", 1336 | "metadata": {}, 1337 | "source": [ 1338 | "# Identity Operator" 1339 | ] 1340 | }, 1341 | { 1342 | "cell_type": "code", 1343 | "execution_count": 17, 1344 | "id": "a5150c23", 1345 | "metadata": {}, 1346 | "outputs": [], 1347 | "source": [ 1348 | "x=10" 1349 | ] 1350 | }, 1351 | { 1352 | "cell_type": "code", 1353 | "execution_count": 18, 1354 | "id": "7fe9c17a", 1355 | "metadata": {}, 1356 | "outputs": [ 1357 | { 1358 | "data": { 1359 | "text/plain": [ 1360 | "True" 1361 | ] 1362 | }, 1363 | "execution_count": 18, 1364 | "metadata": {}, 1365 | "output_type": "execute_result" 1366 | } 1367 | ], 1368 | "source": [ 1369 | "x==10" 1370 | ] 1371 | }, 1372 | { 1373 | "cell_type": "code", 1374 | "execution_count": 19, 1375 | "id": "7936652f", 1376 | "metadata": {}, 1377 | "outputs": [ 1378 | { 1379 | "data": { 1380 | "text/plain": [ 1381 | "True" 1382 | ] 1383 | }, 1384 | "execution_count": 19, 1385 | "metadata": {}, 1386 | "output_type": "execute_result" 1387 | } 1388 | ], 1389 | "source": [ 1390 | "x!=0" 1391 | ] 1392 | }, 1393 | { 1394 | "cell_type": "code", 1395 | "execution_count": 20, 1396 | "id": "41ad1bca", 1397 | "metadata": {}, 1398 | "outputs": [ 1399 | { 1400 | "data": { 1401 | "text/plain": [ 1402 | "False" 1403 | ] 1404 | }, 1405 | "execution_count": 20, 1406 | "metadata": {}, 1407 | "output_type": "execute_result" 1408 | } 1409 | ], 1410 | "source": [ 1411 | "x!=10" 1412 | ] 1413 | }, 1414 | { 1415 | "cell_type": "code", 1416 | "execution_count": 21, 1417 | "id": "5a4418a3", 1418 | "metadata": {}, 1419 | "outputs": [ 1420 | { 1421 | "name": "stderr", 1422 | "output_type": "stream", 1423 | "text": [ 1424 | "<>:1: SyntaxWarning: \"is\" with a literal. Did you mean \"==\"?\n", 1425 | "<>:1: SyntaxWarning: \"is\" with a literal. Did you mean \"==\"?\n", 1426 | "C:\\Users\\RaghulRamesh\\AppData\\Local\\Temp\\ipykernel_9148\\2183931627.py:1: SyntaxWarning: \"is\" with a literal. Did you mean \"==\"?\n", 1427 | " x is 10\n" 1428 | ] 1429 | }, 1430 | { 1431 | "data": { 1432 | "text/plain": [ 1433 | "True" 1434 | ] 1435 | }, 1436 | "execution_count": 21, 1437 | "metadata": {}, 1438 | "output_type": "execute_result" 1439 | } 1440 | ], 1441 | "source": [ 1442 | "x is 10" 1443 | ] 1444 | }, 1445 | { 1446 | "cell_type": "code", 1447 | "execution_count": 22, 1448 | "id": "dc778752", 1449 | "metadata": {}, 1450 | "outputs": [ 1451 | { 1452 | "name": "stderr", 1453 | "output_type": "stream", 1454 | "text": [ 1455 | "<>:1: SyntaxWarning: \"is not\" with a literal. Did you mean \"!=\"?\n", 1456 | "<>:1: SyntaxWarning: \"is not\" with a literal. Did you mean \"!=\"?\n", 1457 | "C:\\Users\\RaghulRamesh\\AppData\\Local\\Temp\\ipykernel_9148\\1660080432.py:1: SyntaxWarning: \"is not\" with a literal. Did you mean \"!=\"?\n", 1458 | " x is not 10\n" 1459 | ] 1460 | }, 1461 | { 1462 | "data": { 1463 | "text/plain": [ 1464 | "False" 1465 | ] 1466 | }, 1467 | "execution_count": 22, 1468 | "metadata": {}, 1469 | "output_type": "execute_result" 1470 | } 1471 | ], 1472 | "source": [ 1473 | "x is not 10" 1474 | ] 1475 | }, 1476 | { 1477 | "cell_type": "code", 1478 | "execution_count": 23, 1479 | "id": "db779977", 1480 | "metadata": {}, 1481 | "outputs": [ 1482 | { 1483 | "name": "stderr", 1484 | "output_type": "stream", 1485 | "text": [ 1486 | "<>:1: SyntaxWarning: \"is not\" with a literal. Did you mean \"!=\"?\n", 1487 | "<>:1: SyntaxWarning: \"is not\" with a literal. Did you mean \"!=\"?\n", 1488 | "C:\\Users\\RaghulRamesh\\AppData\\Local\\Temp\\ipykernel_9148\\3620244120.py:1: SyntaxWarning: \"is not\" with a literal. Did you mean \"!=\"?\n", 1489 | " x is not 100\n" 1490 | ] 1491 | }, 1492 | { 1493 | "data": { 1494 | "text/plain": [ 1495 | "True" 1496 | ] 1497 | }, 1498 | "execution_count": 23, 1499 | "metadata": {}, 1500 | "output_type": "execute_result" 1501 | } 1502 | ], 1503 | "source": [ 1504 | "x is not 100" 1505 | ] 1506 | }, 1507 | { 1508 | "cell_type": "code", 1509 | "execution_count": null, 1510 | "id": "e2f55e9f", 1511 | "metadata": {}, 1512 | "outputs": [], 1513 | "source": [] 1514 | } 1515 | ], 1516 | "metadata": { 1517 | "kernelspec": { 1518 | "display_name": "Python 3 (ipykernel)", 1519 | "language": "python", 1520 | "name": "python3" 1521 | }, 1522 | "language_info": { 1523 | "codemirror_mode": { 1524 | "name": "ipython", 1525 | "version": 3 1526 | }, 1527 | "file_extension": ".py", 1528 | "mimetype": "text/x-python", 1529 | "name": "python", 1530 | "nbconvert_exporter": "python", 1531 | "pygments_lexer": "ipython3", 1532 | "version": "3.8.10" 1533 | } 1534 | }, 1535 | "nbformat": 4, 1536 | "nbformat_minor": 5 1537 | } 1538 | -------------------------------------------------------------------------------- /Operators and Loops Questions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RaghulRameshTrainer/ExcelR_Python_08June2022/1f15cb1d4bbb1237219058b106a4e71d9c28c50a/Operators and Loops Questions.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ExcelR_Python_08June2022 2 | -------------------------------------------------------------------------------- /String_Exercises.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RaghulRameshTrainer/ExcelR_Python_08June2022/1f15cb1d4bbb1237219058b106a4e71d9c28c50a/String_Exercises.pdf -------------------------------------------------------------------------------- /companytest.csv: -------------------------------------------------------------------------------- 1 | Company,Age,Salary 2 | Infosys',20, 3 | CTS,30, 4 | Infosys',35,2300 5 | CTS,40,3000 6 | Infosys,23,4000 7 | CTS,,5000 8 | Infosys,,6000 9 | CTS',23,7000 10 | Infosys,34,8000 11 | TCS,45,9000 12 | TCS,23, 13 | TCS,34,1089 14 | TCS,45, 15 | TCS,18,1234 16 | ,40,3000 17 | Infosys,23,3000 18 | CTS,23,3030 19 | Infosys,34,5000 20 | ,22, 21 | CTS,32, 22 | Infosys,37,3045 23 | CTS,50,3184 24 | Infosys,21,4824 25 | CTS,,5835 26 | ,,7084 27 | CTS,23,8943 28 | Infosys,34,8345 29 | TCS,45,9284 30 | TCS,23, 31 | TCS,35,2034 32 | -------------------------------------------------------------------------------- /cvs_fileformat.py: -------------------------------------------------------------------------------- 1 | import csv 2 | 3 | # with open(r'C:\Users\RaghulRamesh\OneDrive\Documents\data\employee.csv','r') as rf: 4 | # data=csv.reader(rf) 5 | # for row in data: 6 | # print(row[0], row[1],row[4]) 7 | # 8 | with open(r'tech.csv','w',newline='') as wf: 9 | tech=csv.writer(wf) 10 | #tech.writerow(["SN","Tech_Name","Exp"]) 11 | tech.writerow([1,"Python",16]) 12 | tech.writerow([2,"AIML",15]) 13 | tech.writerows([[3,'BigData',11],[4,'Snowflakes',6]]) -------------------------------------------------------------------------------- /datetime_directives.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RaghulRameshTrainer/ExcelR_Python_08June2022/1f15cb1d4bbb1237219058b106a4e71d9c28c50a/datetime_directives.txt -------------------------------------------------------------------------------- /db_ops.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | dbh=sqlite3.connect('excelR.db') 3 | c=dbh.cursor() 4 | 5 | def create_table(): 6 | c.execute("CREATE TABLE employee(empid REAL, ename REAL, tech REAL)") 7 | def load_data(): 8 | id=int(input("Enter your Empid:")) 9 | name=input("Enter your name:") 10 | skill=input("Enter your technology:") 11 | c.execute("INSERT INTO employee VALUES(?,?,?)",(id,name,skill)) 12 | def update_data(): 13 | c.execute("UPDATE employee SET tech='Web Technology' WHERE tech='Java'") 14 | def delete_data(): 15 | c.execute("DELETE FROM employee WHERE tech='AIML'") 16 | def read_data(): 17 | c.execute("SELECT * FROM employee") 18 | #print(c.fetchone()) 19 | #print(c.fetchmany(5)) 20 | for row in c.fetchall(): 21 | print(row[1].upper() + " ===> "+ row[2].upper()) 22 | 23 | #create_table() 24 | # for x in range(5): 25 | # load_data() 26 | #update_data() 27 | #delete_data() 28 | read_data() 29 | # dbh.commit() 30 | # c.close() 31 | # dbh.close() -------------------------------------------------------------------------------- /definitions.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "id": "0977d6c6", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "1. Modularity\n", 11 | "2. Readability\n", 12 | "3. redundancy\n", 13 | "\n", 14 | "10 lines of code\n", 15 | "\n", 16 | "50 time => 50*10=>500" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 1, 22 | "id": "6d9867ed", 23 | "metadata": {}, 24 | "outputs": [], 25 | "source": [ 26 | "def add_nums(x,y):\n", 27 | " res=x+y\n", 28 | " return res" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 2, 34 | "id": "2d2999c9", 35 | "metadata": {}, 36 | "outputs": [ 37 | { 38 | "data": { 39 | "text/plain": [ 40 | "30" 41 | ] 42 | }, 43 | "execution_count": 2, 44 | "metadata": {}, 45 | "output_type": "execute_result" 46 | } 47 | ], 48 | "source": [ 49 | "add_nums(10,20)" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": 5, 55 | "id": "c85e576a", 56 | "metadata": {}, 57 | "outputs": [ 58 | { 59 | "ename": "TypeError", 60 | "evalue": "add_nums() missing 1 required positional argument: 'y'", 61 | "output_type": "error", 62 | "traceback": [ 63 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 64 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 65 | "Input \u001b[1;32mIn [5]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43madd_nums\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m10\u001b[39;49m\u001b[43m)\u001b[49m\n", 66 | "\u001b[1;31mTypeError\u001b[0m: add_nums() missing 1 required positional argument: 'y'" 67 | ] 68 | } 69 | ], 70 | "source": [ 71 | "add_nums(10)" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": 24, 77 | "id": "c72b4d36", 78 | "metadata": {}, 79 | "outputs": [], 80 | "source": [ 81 | "def add_nums(x,y=0): # Default variable\n", 82 | " res=x+y\n", 83 | " return res" 84 | ] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": 7, 89 | "id": "87f88092", 90 | "metadata": {}, 91 | "outputs": [ 92 | { 93 | "data": { 94 | "text/plain": [ 95 | "11" 96 | ] 97 | }, 98 | "execution_count": 7, 99 | "metadata": {}, 100 | "output_type": "execute_result" 101 | } 102 | ], 103 | "source": [ 104 | "add_nums(5,6)" 105 | ] 106 | }, 107 | { 108 | "cell_type": "code", 109 | "execution_count": 8, 110 | "id": "fd7f7ac2", 111 | "metadata": {}, 112 | "outputs": [ 113 | { 114 | "data": { 115 | "text/plain": [ 116 | "5" 117 | ] 118 | }, 119 | "execution_count": 8, 120 | "metadata": {}, 121 | "output_type": "execute_result" 122 | } 123 | ], 124 | "source": [ 125 | "add_nums(5)" 126 | ] 127 | }, 128 | { 129 | "cell_type": "code", 130 | "execution_count": 13, 131 | "id": "1ea71d9e", 132 | "metadata": {}, 133 | "outputs": [], 134 | "source": [ 135 | "def add_nums(x=0,y=5): # Default variable\n", 136 | " res=x+y\n", 137 | " return res" 138 | ] 139 | }, 140 | { 141 | "cell_type": "code", 142 | "execution_count": 14, 143 | "id": "b799f3ea", 144 | "metadata": {}, 145 | "outputs": [ 146 | { 147 | "data": { 148 | "text/plain": [ 149 | "30" 150 | ] 151 | }, 152 | "execution_count": 14, 153 | "metadata": {}, 154 | "output_type": "execute_result" 155 | } 156 | ], 157 | "source": [ 158 | "add_nums(10,20)" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": 15, 164 | "id": "74c1fed2", 165 | "metadata": {}, 166 | "outputs": [ 167 | { 168 | "data": { 169 | "text/plain": [ 170 | "15" 171 | ] 172 | }, 173 | "execution_count": 15, 174 | "metadata": {}, 175 | "output_type": "execute_result" 176 | } 177 | ], 178 | "source": [ 179 | "add_nums(10)" 180 | ] 181 | }, 182 | { 183 | "cell_type": "code", 184 | "execution_count": 16, 185 | "id": "153890dc", 186 | "metadata": {}, 187 | "outputs": [ 188 | { 189 | "data": { 190 | "text/plain": [ 191 | "5" 192 | ] 193 | }, 194 | "execution_count": 16, 195 | "metadata": {}, 196 | "output_type": "execute_result" 197 | } 198 | ], 199 | "source": [ 200 | "add_nums()" 201 | ] 202 | }, 203 | { 204 | "cell_type": "code", 205 | "execution_count": 17, 206 | "id": "62b01eb5", 207 | "metadata": {}, 208 | "outputs": [ 209 | { 210 | "ename": "TypeError", 211 | "evalue": "add_nums() takes from 0 to 2 positional arguments but 5 were given", 212 | "output_type": "error", 213 | "traceback": [ 214 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 215 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 216 | "Input \u001b[1;32mIn [17]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43madd_nums\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m10\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;241;43m20\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;241;43m30\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;241;43m40\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;241;43m50\u001b[39;49m\u001b[43m)\u001b[49m\n", 217 | "\u001b[1;31mTypeError\u001b[0m: add_nums() takes from 0 to 2 positional arguments but 5 were given" 218 | ] 219 | } 220 | ], 221 | "source": [ 222 | "add_nums(10,20,30,40,50)" 223 | ] 224 | }, 225 | { 226 | "cell_type": "code", 227 | "execution_count": 21, 228 | "id": "960965b9", 229 | "metadata": {}, 230 | "outputs": [], 231 | "source": [ 232 | "def add_nums(x,y,*z):\n", 233 | " print(\"type of x :{} and value is : {}\".format(type(x),x))\n", 234 | " print(\"type of y :{} and value is : {}\".format(type(y),y))\n", 235 | " print(\"type of z :{} and value is : {}\".format(type(z),z))" 236 | ] 237 | }, 238 | { 239 | "cell_type": "code", 240 | "execution_count": 22, 241 | "id": "31c2f096", 242 | "metadata": {}, 243 | "outputs": [ 244 | { 245 | "name": "stdout", 246 | "output_type": "stream", 247 | "text": [ 248 | "type of x : and value is : 10\n", 249 | "type of y : and value is : 20\n", 250 | "type of z : and value is : (30, 40, 50)\n" 251 | ] 252 | } 253 | ], 254 | "source": [ 255 | "add_nums(10,20,30,40,50)" 256 | ] 257 | }, 258 | { 259 | "cell_type": "code", 260 | "execution_count": 25, 261 | "id": "7f953a8a", 262 | "metadata": {}, 263 | "outputs": [], 264 | "source": [ 265 | "def add_nums(x,y,*z):\n", 266 | " res=x+y+sum(z)\n", 267 | " return res" 268 | ] 269 | }, 270 | { 271 | "cell_type": "code", 272 | "execution_count": 26, 273 | "id": "7e79cc87", 274 | "metadata": {}, 275 | "outputs": [ 276 | { 277 | "data": { 278 | "text/plain": [ 279 | "150" 280 | ] 281 | }, 282 | "execution_count": 26, 283 | "metadata": {}, 284 | "output_type": "execute_result" 285 | } 286 | ], 287 | "source": [ 288 | "add_nums(10,20,30,40,50)" 289 | ] 290 | }, 291 | { 292 | "cell_type": "code", 293 | "execution_count": 27, 294 | "id": "f3c3351d", 295 | "metadata": {}, 296 | "outputs": [ 297 | { 298 | "data": { 299 | "text/plain": [ 300 | "60" 301 | ] 302 | }, 303 | "execution_count": 27, 304 | "metadata": {}, 305 | "output_type": "execute_result" 306 | } 307 | ], 308 | "source": [ 309 | "add_nums(10,20,30)" 310 | ] 311 | }, 312 | { 313 | "cell_type": "code", 314 | "execution_count": 28, 315 | "id": "177a0e4e", 316 | "metadata": {}, 317 | "outputs": [ 318 | { 319 | "data": { 320 | "text/plain": [ 321 | "30" 322 | ] 323 | }, 324 | "execution_count": 28, 325 | "metadata": {}, 326 | "output_type": "execute_result" 327 | } 328 | ], 329 | "source": [ 330 | "add_nums(10,20)" 331 | ] 332 | }, 333 | { 334 | "cell_type": "code", 335 | "execution_count": 29, 336 | "id": "f02d530e", 337 | "metadata": {}, 338 | "outputs": [], 339 | "source": [ 340 | "def add_nums(x,y=0,*z):\n", 341 | " res=x+y+sum(z)\n", 342 | " return res" 343 | ] 344 | }, 345 | { 346 | "cell_type": "code", 347 | "execution_count": 30, 348 | "id": "bc36e4c8", 349 | "metadata": {}, 350 | "outputs": [ 351 | { 352 | "data": { 353 | "text/plain": [ 354 | "10" 355 | ] 356 | }, 357 | "execution_count": 30, 358 | "metadata": {}, 359 | "output_type": "execute_result" 360 | } 361 | ], 362 | "source": [ 363 | "add_nums(10)" 364 | ] 365 | }, 366 | { 367 | "cell_type": "code", 368 | "execution_count": 31, 369 | "id": "ad1b3fb3", 370 | "metadata": {}, 371 | "outputs": [ 372 | { 373 | "data": { 374 | "text/plain": [ 375 | "30" 376 | ] 377 | }, 378 | "execution_count": 31, 379 | "metadata": {}, 380 | "output_type": "execute_result" 381 | } 382 | ], 383 | "source": [ 384 | "add_nums(10,20)" 385 | ] 386 | }, 387 | { 388 | "cell_type": "code", 389 | "execution_count": 32, 390 | "id": "da1bb7bb", 391 | "metadata": {}, 392 | "outputs": [ 393 | { 394 | "data": { 395 | "text/plain": [ 396 | "60" 397 | ] 398 | }, 399 | "execution_count": 32, 400 | "metadata": {}, 401 | "output_type": "execute_result" 402 | } 403 | ], 404 | "source": [ 405 | "add_nums(10,20,30)" 406 | ] 407 | }, 408 | { 409 | "cell_type": "code", 410 | "execution_count": 33, 411 | "id": "2c2bbfb1", 412 | "metadata": {}, 413 | "outputs": [ 414 | { 415 | "data": { 416 | "text/plain": [ 417 | "100" 418 | ] 419 | }, 420 | "execution_count": 33, 421 | "metadata": {}, 422 | "output_type": "execute_result" 423 | } 424 | ], 425 | "source": [ 426 | "add_nums(10,20,30,40)" 427 | ] 428 | }, 429 | { 430 | "cell_type": "code", 431 | "execution_count": 42, 432 | "id": "c30a26b3", 433 | "metadata": {}, 434 | "outputs": [], 435 | "source": [ 436 | "def add_nums(x,y):\n", 437 | " '''add_nums function takes 2 numbers as an input and perform sum of them'''\n", 438 | " res=x+y\n", 439 | " return res" 440 | ] 441 | }, 442 | { 443 | "cell_type": "code", 444 | "execution_count": 43, 445 | "id": "1cc7b476", 446 | "metadata": {}, 447 | "outputs": [ 448 | { 449 | "data": { 450 | "text/plain": [ 451 | "'add_nums function takes 2 numbers as an input and perform sum of them'" 452 | ] 453 | }, 454 | "execution_count": 43, 455 | "metadata": {}, 456 | "output_type": "execute_result" 457 | } 458 | ], 459 | "source": [ 460 | "add_nums.__doc__" 461 | ] 462 | }, 463 | { 464 | "cell_type": "code", 465 | "execution_count": 44, 466 | "id": "e99d9c42", 467 | "metadata": {}, 468 | "outputs": [ 469 | { 470 | "data": { 471 | "text/plain": [ 472 | "300" 473 | ] 474 | }, 475 | "execution_count": 44, 476 | "metadata": {}, 477 | "output_type": "execute_result" 478 | } 479 | ], 480 | "source": [ 481 | "add_nums(100,200)" 482 | ] 483 | }, 484 | { 485 | "cell_type": "code", 486 | "execution_count": 46, 487 | "id": "c525ae33", 488 | "metadata": {}, 489 | "outputs": [], 490 | "source": [ 491 | "def myfunc(x,y=0,*z,**k): # *args , **kwargs\n", 492 | " print(\"x:{} , y:{}, z:{} , k:{}\".format(x,y,z,k))" 493 | ] 494 | }, 495 | { 496 | "cell_type": "code", 497 | "execution_count": 47, 498 | "id": "f8a4407c", 499 | "metadata": {}, 500 | "outputs": [ 501 | { 502 | "name": "stdout", 503 | "output_type": "stream", 504 | "text": [ 505 | "x:10 , y:20, z:(30, 40, 50) , k:{'name': 'Raghul Ramesh', 'city': 'Chennai', 'tech': 'Python'}\n" 506 | ] 507 | } 508 | ], 509 | "source": [ 510 | "myfunc(10,20,30,40,50,name='Raghul Ramesh', city='Chennai', tech='Python')" 511 | ] 512 | }, 513 | { 514 | "cell_type": "code", 515 | "execution_count": 57, 516 | "id": "e1e2d486", 517 | "metadata": {}, 518 | "outputs": [], 519 | "source": [ 520 | "def course_info(**x):\n", 521 | " print(x)\n", 522 | " for k in x.keys():\n", 523 | " print(k + \" ===> \"+ str(x[k]))" 524 | ] 525 | }, 526 | { 527 | "cell_type": "code", 528 | "execution_count": 58, 529 | "id": "2f1fed76", 530 | "metadata": {}, 531 | "outputs": [ 532 | { 533 | "name": "stdout", 534 | "output_type": "stream", 535 | "text": [ 536 | "{'mode': 'online', 'tech': 'AI', 'duration': 90, 'current_topic': 'Python'}\n", 537 | "mode ===> online\n", 538 | "tech ===> AI\n", 539 | "duration ===> 90\n", 540 | "current_topic ===> Python\n" 541 | ] 542 | } 543 | ], 544 | "source": [ 545 | "course_info(mode='online', tech='AI', duration=90 , current_topic='Python')" 546 | ] 547 | }, 548 | { 549 | "cell_type": "code", 550 | "execution_count": null, 551 | "id": "53fb5a57", 552 | "metadata": {}, 553 | "outputs": [], 554 | "source": [ 555 | "# Why do we need to go for a function\n", 556 | "# How to create a function\n", 557 | "# different parameters used in funcitons: mandatory, optional, *args, **kwargs\n", 558 | "# function may or may not have a return statement\n", 559 | "# documentory string " 560 | ] 561 | }, 562 | { 563 | "cell_type": "code", 564 | "execution_count": null, 565 | "id": "dd59a64e", 566 | "metadata": {}, 567 | "outputs": [], 568 | "source": [ 569 | "# SCOPE OF THE VARIABLE IN FUNCTION ( local, global)" 570 | ] 571 | } 572 | ], 573 | "metadata": { 574 | "kernelspec": { 575 | "display_name": "Python 3 (ipykernel)", 576 | "language": "python", 577 | "name": "python3" 578 | }, 579 | "language_info": { 580 | "codemirror_mode": { 581 | "name": "ipython", 582 | "version": 3 583 | }, 584 | "file_extension": ".py", 585 | "mimetype": "text/x-python", 586 | "name": "python", 587 | "nbconvert_exporter": "python", 588 | "pygments_lexer": "ipython3", 589 | "version": "3.8.10" 590 | } 591 | }, 592 | "nbformat": 4, 593 | "nbformat_minor": 5 594 | } 595 | -------------------------------------------------------------------------------- /definitions_update.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "id": "0977d6c6", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "1. Modularity\n", 11 | "2. Readability\n", 12 | "3. redundancy\n", 13 | "\n", 14 | "10 lines of code\n", 15 | "\n", 16 | "50 time => 50*10=>500" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 1, 22 | "id": "6d9867ed", 23 | "metadata": {}, 24 | "outputs": [], 25 | "source": [ 26 | "def add_nums(x,y):\n", 27 | " res=x+y\n", 28 | " return res" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 2, 34 | "id": "2d2999c9", 35 | "metadata": {}, 36 | "outputs": [ 37 | { 38 | "data": { 39 | "text/plain": [ 40 | "30" 41 | ] 42 | }, 43 | "execution_count": 2, 44 | "metadata": {}, 45 | "output_type": "execute_result" 46 | } 47 | ], 48 | "source": [ 49 | "add_nums(10,20)" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": 5, 55 | "id": "c85e576a", 56 | "metadata": {}, 57 | "outputs": [ 58 | { 59 | "ename": "TypeError", 60 | "evalue": "add_nums() missing 1 required positional argument: 'y'", 61 | "output_type": "error", 62 | "traceback": [ 63 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 64 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 65 | "Input \u001b[1;32mIn [5]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43madd_nums\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m10\u001b[39;49m\u001b[43m)\u001b[49m\n", 66 | "\u001b[1;31mTypeError\u001b[0m: add_nums() missing 1 required positional argument: 'y'" 67 | ] 68 | } 69 | ], 70 | "source": [ 71 | "add_nums(10)" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": 24, 77 | "id": "c72b4d36", 78 | "metadata": {}, 79 | "outputs": [], 80 | "source": [ 81 | "def add_nums(x,y=0): # Default variable\n", 82 | " res=x+y\n", 83 | " return res" 84 | ] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": 7, 89 | "id": "87f88092", 90 | "metadata": {}, 91 | "outputs": [ 92 | { 93 | "data": { 94 | "text/plain": [ 95 | "11" 96 | ] 97 | }, 98 | "execution_count": 7, 99 | "metadata": {}, 100 | "output_type": "execute_result" 101 | } 102 | ], 103 | "source": [ 104 | "add_nums(5,6)" 105 | ] 106 | }, 107 | { 108 | "cell_type": "code", 109 | "execution_count": 8, 110 | "id": "fd7f7ac2", 111 | "metadata": {}, 112 | "outputs": [ 113 | { 114 | "data": { 115 | "text/plain": [ 116 | "5" 117 | ] 118 | }, 119 | "execution_count": 8, 120 | "metadata": {}, 121 | "output_type": "execute_result" 122 | } 123 | ], 124 | "source": [ 125 | "add_nums(5)" 126 | ] 127 | }, 128 | { 129 | "cell_type": "code", 130 | "execution_count": 13, 131 | "id": "1ea71d9e", 132 | "metadata": {}, 133 | "outputs": [], 134 | "source": [ 135 | "def add_nums(x=0,y=5): # Default variable\n", 136 | " res=x+y\n", 137 | " return res" 138 | ] 139 | }, 140 | { 141 | "cell_type": "code", 142 | "execution_count": 14, 143 | "id": "b799f3ea", 144 | "metadata": {}, 145 | "outputs": [ 146 | { 147 | "data": { 148 | "text/plain": [ 149 | "30" 150 | ] 151 | }, 152 | "execution_count": 14, 153 | "metadata": {}, 154 | "output_type": "execute_result" 155 | } 156 | ], 157 | "source": [ 158 | "add_nums(10,20)" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": 15, 164 | "id": "74c1fed2", 165 | "metadata": {}, 166 | "outputs": [ 167 | { 168 | "data": { 169 | "text/plain": [ 170 | "15" 171 | ] 172 | }, 173 | "execution_count": 15, 174 | "metadata": {}, 175 | "output_type": "execute_result" 176 | } 177 | ], 178 | "source": [ 179 | "add_nums(10)" 180 | ] 181 | }, 182 | { 183 | "cell_type": "code", 184 | "execution_count": 16, 185 | "id": "153890dc", 186 | "metadata": {}, 187 | "outputs": [ 188 | { 189 | "data": { 190 | "text/plain": [ 191 | "5" 192 | ] 193 | }, 194 | "execution_count": 16, 195 | "metadata": {}, 196 | "output_type": "execute_result" 197 | } 198 | ], 199 | "source": [ 200 | "add_nums()" 201 | ] 202 | }, 203 | { 204 | "cell_type": "code", 205 | "execution_count": 17, 206 | "id": "62b01eb5", 207 | "metadata": {}, 208 | "outputs": [ 209 | { 210 | "ename": "TypeError", 211 | "evalue": "add_nums() takes from 0 to 2 positional arguments but 5 were given", 212 | "output_type": "error", 213 | "traceback": [ 214 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 215 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 216 | "Input \u001b[1;32mIn [17]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43madd_nums\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m10\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;241;43m20\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;241;43m30\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;241;43m40\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;241;43m50\u001b[39;49m\u001b[43m)\u001b[49m\n", 217 | "\u001b[1;31mTypeError\u001b[0m: add_nums() takes from 0 to 2 positional arguments but 5 were given" 218 | ] 219 | } 220 | ], 221 | "source": [ 222 | "add_nums(10,20,30,40,50)" 223 | ] 224 | }, 225 | { 226 | "cell_type": "code", 227 | "execution_count": 21, 228 | "id": "960965b9", 229 | "metadata": {}, 230 | "outputs": [], 231 | "source": [ 232 | "def add_nums(x,y,*z):\n", 233 | " print(\"type of x :{} and value is : {}\".format(type(x),x))\n", 234 | " print(\"type of y :{} and value is : {}\".format(type(y),y))\n", 235 | " print(\"type of z :{} and value is : {}\".format(type(z),z))" 236 | ] 237 | }, 238 | { 239 | "cell_type": "code", 240 | "execution_count": 22, 241 | "id": "31c2f096", 242 | "metadata": {}, 243 | "outputs": [ 244 | { 245 | "name": "stdout", 246 | "output_type": "stream", 247 | "text": [ 248 | "type of x : and value is : 10\n", 249 | "type of y : and value is : 20\n", 250 | "type of z : and value is : (30, 40, 50)\n" 251 | ] 252 | } 253 | ], 254 | "source": [ 255 | "add_nums(10,20,30,40,50)" 256 | ] 257 | }, 258 | { 259 | "cell_type": "code", 260 | "execution_count": 25, 261 | "id": "7f953a8a", 262 | "metadata": {}, 263 | "outputs": [], 264 | "source": [ 265 | "def add_nums(x,y,*z):\n", 266 | " res=x+y+sum(z)\n", 267 | " return res" 268 | ] 269 | }, 270 | { 271 | "cell_type": "code", 272 | "execution_count": 26, 273 | "id": "7e79cc87", 274 | "metadata": {}, 275 | "outputs": [ 276 | { 277 | "data": { 278 | "text/plain": [ 279 | "150" 280 | ] 281 | }, 282 | "execution_count": 26, 283 | "metadata": {}, 284 | "output_type": "execute_result" 285 | } 286 | ], 287 | "source": [ 288 | "add_nums(10,20,30,40,50)" 289 | ] 290 | }, 291 | { 292 | "cell_type": "code", 293 | "execution_count": 27, 294 | "id": "f3c3351d", 295 | "metadata": {}, 296 | "outputs": [ 297 | { 298 | "data": { 299 | "text/plain": [ 300 | "60" 301 | ] 302 | }, 303 | "execution_count": 27, 304 | "metadata": {}, 305 | "output_type": "execute_result" 306 | } 307 | ], 308 | "source": [ 309 | "add_nums(10,20,30)" 310 | ] 311 | }, 312 | { 313 | "cell_type": "code", 314 | "execution_count": 28, 315 | "id": "177a0e4e", 316 | "metadata": {}, 317 | "outputs": [ 318 | { 319 | "data": { 320 | "text/plain": [ 321 | "30" 322 | ] 323 | }, 324 | "execution_count": 28, 325 | "metadata": {}, 326 | "output_type": "execute_result" 327 | } 328 | ], 329 | "source": [ 330 | "add_nums(10,20)" 331 | ] 332 | }, 333 | { 334 | "cell_type": "code", 335 | "execution_count": 29, 336 | "id": "f02d530e", 337 | "metadata": {}, 338 | "outputs": [], 339 | "source": [ 340 | "def add_nums(x,y=0,*z):\n", 341 | " res=x+y+sum(z)\n", 342 | " return res" 343 | ] 344 | }, 345 | { 346 | "cell_type": "code", 347 | "execution_count": 30, 348 | "id": "bc36e4c8", 349 | "metadata": {}, 350 | "outputs": [ 351 | { 352 | "data": { 353 | "text/plain": [ 354 | "10" 355 | ] 356 | }, 357 | "execution_count": 30, 358 | "metadata": {}, 359 | "output_type": "execute_result" 360 | } 361 | ], 362 | "source": [ 363 | "add_nums(10)" 364 | ] 365 | }, 366 | { 367 | "cell_type": "code", 368 | "execution_count": 31, 369 | "id": "ad1b3fb3", 370 | "metadata": {}, 371 | "outputs": [ 372 | { 373 | "data": { 374 | "text/plain": [ 375 | "30" 376 | ] 377 | }, 378 | "execution_count": 31, 379 | "metadata": {}, 380 | "output_type": "execute_result" 381 | } 382 | ], 383 | "source": [ 384 | "add_nums(10,20)" 385 | ] 386 | }, 387 | { 388 | "cell_type": "code", 389 | "execution_count": 32, 390 | "id": "da1bb7bb", 391 | "metadata": {}, 392 | "outputs": [ 393 | { 394 | "data": { 395 | "text/plain": [ 396 | "60" 397 | ] 398 | }, 399 | "execution_count": 32, 400 | "metadata": {}, 401 | "output_type": "execute_result" 402 | } 403 | ], 404 | "source": [ 405 | "add_nums(10,20,30)" 406 | ] 407 | }, 408 | { 409 | "cell_type": "code", 410 | "execution_count": 33, 411 | "id": "2c2bbfb1", 412 | "metadata": {}, 413 | "outputs": [ 414 | { 415 | "data": { 416 | "text/plain": [ 417 | "100" 418 | ] 419 | }, 420 | "execution_count": 33, 421 | "metadata": {}, 422 | "output_type": "execute_result" 423 | } 424 | ], 425 | "source": [ 426 | "add_nums(10,20,30,40)" 427 | ] 428 | }, 429 | { 430 | "cell_type": "code", 431 | "execution_count": 42, 432 | "id": "c30a26b3", 433 | "metadata": {}, 434 | "outputs": [], 435 | "source": [ 436 | "def add_nums(x,y):\n", 437 | " '''add_nums function takes 2 numbers as an input and perform sum of them'''\n", 438 | " res=x+y\n", 439 | " return res" 440 | ] 441 | }, 442 | { 443 | "cell_type": "code", 444 | "execution_count": 43, 445 | "id": "1cc7b476", 446 | "metadata": {}, 447 | "outputs": [ 448 | { 449 | "data": { 450 | "text/plain": [ 451 | "'add_nums function takes 2 numbers as an input and perform sum of them'" 452 | ] 453 | }, 454 | "execution_count": 43, 455 | "metadata": {}, 456 | "output_type": "execute_result" 457 | } 458 | ], 459 | "source": [ 460 | "add_nums.__doc__" 461 | ] 462 | }, 463 | { 464 | "cell_type": "code", 465 | "execution_count": 44, 466 | "id": "e99d9c42", 467 | "metadata": {}, 468 | "outputs": [ 469 | { 470 | "data": { 471 | "text/plain": [ 472 | "300" 473 | ] 474 | }, 475 | "execution_count": 44, 476 | "metadata": {}, 477 | "output_type": "execute_result" 478 | } 479 | ], 480 | "source": [ 481 | "add_nums(100,200)" 482 | ] 483 | }, 484 | { 485 | "cell_type": "code", 486 | "execution_count": 46, 487 | "id": "c525ae33", 488 | "metadata": {}, 489 | "outputs": [], 490 | "source": [ 491 | "def myfunc(x,y=0,*z,**k): # *args , **kwargs\n", 492 | " print(\"x:{} , y:{}, z:{} , k:{}\".format(x,y,z,k))" 493 | ] 494 | }, 495 | { 496 | "cell_type": "code", 497 | "execution_count": 47, 498 | "id": "f8a4407c", 499 | "metadata": {}, 500 | "outputs": [ 501 | { 502 | "name": "stdout", 503 | "output_type": "stream", 504 | "text": [ 505 | "x:10 , y:20, z:(30, 40, 50) , k:{'name': 'Raghul Ramesh', 'city': 'Chennai', 'tech': 'Python'}\n" 506 | ] 507 | } 508 | ], 509 | "source": [ 510 | "myfunc(10,20,30,40,50,name='Raghul Ramesh', city='Chennai', tech='Python')" 511 | ] 512 | }, 513 | { 514 | "cell_type": "code", 515 | "execution_count": 57, 516 | "id": "e1e2d486", 517 | "metadata": {}, 518 | "outputs": [], 519 | "source": [ 520 | "def course_info(**x):\n", 521 | " print(x)\n", 522 | " for k in x.keys():\n", 523 | " print(k + \" ===> \"+ str(x[k]))" 524 | ] 525 | }, 526 | { 527 | "cell_type": "code", 528 | "execution_count": 58, 529 | "id": "2f1fed76", 530 | "metadata": {}, 531 | "outputs": [ 532 | { 533 | "name": "stdout", 534 | "output_type": "stream", 535 | "text": [ 536 | "{'mode': 'online', 'tech': 'AI', 'duration': 90, 'current_topic': 'Python'}\n", 537 | "mode ===> online\n", 538 | "tech ===> AI\n", 539 | "duration ===> 90\n", 540 | "current_topic ===> Python\n" 541 | ] 542 | } 543 | ], 544 | "source": [ 545 | "course_info(mode='online', tech='AI', duration=90 , current_topic='Python')" 546 | ] 547 | }, 548 | { 549 | "cell_type": "code", 550 | "execution_count": null, 551 | "id": "53fb5a57", 552 | "metadata": {}, 553 | "outputs": [], 554 | "source": [ 555 | "# Why do we need to go for a function\n", 556 | "# How to create a function\n", 557 | "# different parameters used in funcitons: mandatory, optional, *args, **kwargs\n", 558 | "# function may or may not have a return statement\n", 559 | "# documentory string " 560 | ] 561 | }, 562 | { 563 | "cell_type": "code", 564 | "execution_count": null, 565 | "id": "dd59a64e", 566 | "metadata": {}, 567 | "outputs": [], 568 | "source": [ 569 | "# SCOPE OF THE VARIABLE IN FUNCTION ( local, global)" 570 | ] 571 | }, 572 | { 573 | "cell_type": "code", 574 | "execution_count": 7, 575 | "id": "5be083cb", 576 | "metadata": {}, 577 | "outputs": [ 578 | { 579 | "name": "stdout", 580 | "output_type": "stream", 581 | "text": [ 582 | "Session From: Hyderabad\n" 583 | ] 584 | } 585 | ], 586 | "source": [ 587 | "city='Hyderabad' #global varible\n", 588 | "def scope_ex():\n", 589 | " #city='Chennai' #local variable\n", 590 | " print(\"Hometown: \",city)\n", 591 | " \n", 592 | "print(\"Session From:\", city)" 593 | ] 594 | }, 595 | { 596 | "cell_type": "code", 597 | "execution_count": 8, 598 | "id": "d48646d7", 599 | "metadata": {}, 600 | "outputs": [ 601 | { 602 | "name": "stdout", 603 | "output_type": "stream", 604 | "text": [ 605 | "Hometown: Hyderabad\n" 606 | ] 607 | } 608 | ], 609 | "source": [ 610 | "scope_ex()" 611 | ] 612 | }, 613 | { 614 | "cell_type": "code", 615 | "execution_count": 9, 616 | "id": "98e7392c", 617 | "metadata": {}, 618 | "outputs": [ 619 | { 620 | "name": "stdout", 621 | "output_type": "stream", 622 | "text": [ 623 | "Age before the function call : 37\n", 624 | "Age inside the function : 100\n", 625 | "Age after the function call : 37\n" 626 | ] 627 | } 628 | ], 629 | "source": [ 630 | "age=37\n", 631 | "\n", 632 | "def callme():\n", 633 | " age=100\n", 634 | " print('Age inside the function : ', age)\n", 635 | " \n", 636 | "print('Age before the function call : ', age) # 37\n", 637 | "callme() #100\n", 638 | "print('Age after the function call : ',age) #37" 639 | ] 640 | }, 641 | { 642 | "cell_type": "code", 643 | "execution_count": 11, 644 | "id": "38065021", 645 | "metadata": {}, 646 | "outputs": [ 647 | { 648 | "name": "stdout", 649 | "output_type": "stream", 650 | "text": [ 651 | "Age before the function call : 37\n", 652 | "Age inside the function : 100\n", 653 | "Age after the function call : 100\n" 654 | ] 655 | } 656 | ], 657 | "source": [ 658 | "age=37\n", 659 | "\n", 660 | "def myfunc():\n", 661 | " global age\n", 662 | " age=100\n", 663 | " print('Age inside the function : ', age)\n", 664 | " \n", 665 | "print('Age before the function call : ', age) # 37\n", 666 | "myfunc() #100\n", 667 | "print('Age after the function call : ',age) #37" 668 | ] 669 | }, 670 | { 671 | "cell_type": "code", 672 | "execution_count": null, 673 | "id": "17597f7c", 674 | "metadata": {}, 675 | "outputs": [], 676 | "source": [] 677 | } 678 | ], 679 | "metadata": { 680 | "kernelspec": { 681 | "display_name": "Python 3 (ipykernel)", 682 | "language": "python", 683 | "name": "python3" 684 | }, 685 | "language_info": { 686 | "codemirror_mode": { 687 | "name": "ipython", 688 | "version": 3 689 | }, 690 | "file_extension": ".py", 691 | "mimetype": "text/x-python", 692 | "name": "python", 693 | "nbconvert_exporter": "python", 694 | "pygments_lexer": "ipython3", 695 | "version": "3.8.10" 696 | } 697 | }, 698 | "nbformat": 4, 699 | "nbformat_minor": 5 700 | } 701 | -------------------------------------------------------------------------------- /excelr_junebatch.py: -------------------------------------------------------------------------------- 1 | age=200 2 | if age>18 and age<=100: 3 | print("You can vote") 4 | print("It is valid only for indian citizen") 5 | print("Please check your own contry standards if you are from other country") 6 | elif age<0 or age>100: 7 | print("Invalid age. Please check") 8 | elif age==0: 9 | print("You are a just born baby!") 10 | else: 11 | print("You cannot vote") 12 | print("Because you are less than 18 years old") 13 | print("Out of conditional statement") -------------------------------------------------------------------------------- /file_ops.py: -------------------------------------------------------------------------------- 1 | ''' 2 | with open(filename, mode) as fh: 3 | pass 4 | mode 5 | r (read)-> Open the file to read, File must exists. If the file is not there then 6 | we will get FileNotFoundError 7 | read(), readline(), readlines() 8 | w (write) -> Open the file for writing . If the file is not there it will create a 9 | file and write into it. OR if the file is there, then it will cleanup 10 | the file content and start writing as a new file 11 | write(), writelines() 12 | a (append) -> similar to write except it will not remove the file content, it will 13 | continue to add the content along with the existing data 14 | r+( read and write) -> file we must read the existing content and start writing into it 15 | w+ ( write and read) -> write first and read whatever has been written 16 | rb (read binary) -> image,video,audio 17 | wb (write binary) 18 | ''' 19 | 20 | #with open('day.txt','r') as fo: 21 | #print(fo.read()) 22 | # print(fo.readline(),end='') 23 | # print(fo.readline()) 24 | #print(fo.readlines()[1:6]) 25 | # for day in fo.readlines()[1:6]: 26 | # print(day.upper(),end='') 27 | 28 | # with open(r'D:\data\tech.txt') as fh: 29 | # print(fh.read()) 30 | 31 | # with open(r'D:\data\tech.txt','w') as fh: 32 | # fh.writelines(["Data Analytics\n","PowerBI"]) 33 | 34 | # with open(r'D:\data\tech.txt', 'a') as fh: 35 | # fh.writelines(["\nMySQL\n", "R"]) 36 | 37 | # with open('day.txt','r+') as fh: 38 | # print(fh.read()) 39 | # fh.writelines(['\nINDIA\n','PAKISTAN']) 40 | # # fh.writelines(['Artificial Intellegence , Machine Learning\n','Deep Learning']) 41 | # # print(fh.read()) 42 | 43 | # with open('day.txt','w+') as fo: 44 | # fo.writelines(['Chennai\n','Bangalore\n','Hyderabad\n','Pune\n','Delhi']) 45 | # fo.seek(0,0) 46 | # print(fo.read()) 47 | 48 | # with open('day.txt') as rf: 49 | # with open('city.txt','a') as wf: 50 | # data=rf.readlines() 51 | # wf.writelines(data[0:2]) 52 | # wf.writelines(['Cochin\n','Kolkatta\n']) 53 | # wf.writelines(data[2:]) 54 | 55 | with open(r'C:\Users\RaghulRamesh\OneDrive\Pictures\puppy.jpg','rb') as pp: 56 | with open(r'C:\Users\RaghulRamesh\OneDrive\Pictures\puppy_new.jpg', 'wb') as wp: 57 | wp.write(pp.read()) -------------------------------------------------------------------------------- /json_ex.py: -------------------------------------------------------------------------------- 1 | import json 2 | # with open(r'C:\Users\RaghulRamesh\OneDrive\Documents\data\sample.json','r') as jf: 3 | # data=json.load(jf) 4 | # for x in data['people'][0].keys(): 5 | # print(x + " ===> "+ str(data['people'][0][x] )) 6 | 7 | info={ 8 | 'Name':'Raghul Ramesh', 9 | 'City':'Chennai', 10 | 'Tech':['Python','AIML','AWS'], 11 | 'Manager': False, 12 | 'Salary':None 13 | } 14 | 15 | with open('trainer_info.json','w') as wjf: 16 | json.dump(info,wjf) -------------------------------------------------------------------------------- /logging_ex.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | ''' LEVELS: 4 | DEBUG 10 5 | INFO 20 6 | WARNING 30 7 | ERROR 40 8 | CRITICAL 50 9 | ''' 10 | logging.basicConfig(filename='output.log', 11 | level=logging.DEBUG, 12 | format="%(levelname)s %(asctime)s - %(message)s") 13 | logger=logging.getLogger() 14 | logger.debug("Debug message") 15 | logger.info("Info messages") 16 | logger.warning("Warning message") 17 | logger.error("Error message") 18 | logger.critical("Critical Messages") -------------------------------------------------------------------------------- /numpy.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "id": "73ef9940", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "import numpy as np" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 2, 16 | "id": "f2f00d1f", 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "a=np.array([1,2,3])" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 3, 26 | "id": "cf62d67e", 27 | "metadata": {}, 28 | "outputs": [ 29 | { 30 | "data": { 31 | "text/plain": [ 32 | "array([1, 2, 3])" 33 | ] 34 | }, 35 | "execution_count": 3, 36 | "metadata": {}, 37 | "output_type": "execute_result" 38 | } 39 | ], 40 | "source": [ 41 | "a" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": 4, 47 | "id": "7e96503b", 48 | "metadata": {}, 49 | "outputs": [ 50 | { 51 | "name": "stdout", 52 | "output_type": "stream", 53 | "text": [ 54 | "[1 2 3]\n" 55 | ] 56 | } 57 | ], 58 | "source": [ 59 | "print(a)" 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": 5, 65 | "id": "a633b9a4", 66 | "metadata": {}, 67 | "outputs": [], 68 | "source": [ 69 | "a=np.array([(1,2,3),(4,5,6)])" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 6, 75 | "id": "c119cd4e", 76 | "metadata": {}, 77 | "outputs": [ 78 | { 79 | "name": "stdout", 80 | "output_type": "stream", 81 | "text": [ 82 | "[[1 2 3]\n", 83 | " [4 5 6]]\n" 84 | ] 85 | } 86 | ], 87 | "source": [ 88 | "print(a)" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": 7, 94 | "id": "0f110e95", 95 | "metadata": {}, 96 | "outputs": [ 97 | { 98 | "name": "stdout", 99 | "output_type": "stream", 100 | "text": [ 101 | "280000\n" 102 | ] 103 | } 104 | ], 105 | "source": [ 106 | "import sys\n", 107 | "\n", 108 | "L=range(10000)\n", 109 | "print(sys.getsizeof(5)*len(L))" 110 | ] 111 | }, 112 | { 113 | "cell_type": "code", 114 | "execution_count": 15, 115 | "id": "7bbf7217", 116 | "metadata": {}, 117 | "outputs": [ 118 | { 119 | "name": "stdout", 120 | "output_type": "stream", 121 | "text": [ 122 | "10000\n" 123 | ] 124 | } 125 | ], 126 | "source": [ 127 | "A=np.arange(10000,dtype='int8')\n", 128 | "print(A.itemsize * A.size)" 129 | ] 130 | }, 131 | { 132 | "cell_type": "code", 133 | "execution_count": 9, 134 | "id": "605cc113", 135 | "metadata": {}, 136 | "outputs": [ 137 | { 138 | "data": { 139 | "text/plain": [ 140 | "array([[1, 2, 3],\n", 141 | " [4, 5, 6]])" 142 | ] 143 | }, 144 | "execution_count": 9, 145 | "metadata": {}, 146 | "output_type": "execute_result" 147 | } 148 | ], 149 | "source": [ 150 | "a" 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "execution_count": 10, 156 | "id": "676c0e29", 157 | "metadata": {}, 158 | "outputs": [ 159 | { 160 | "data": { 161 | "text/plain": [ 162 | "4" 163 | ] 164 | }, 165 | "execution_count": 10, 166 | "metadata": {}, 167 | "output_type": "execute_result" 168 | } 169 | ], 170 | "source": [ 171 | "a.itemsize" 172 | ] 173 | }, 174 | { 175 | "cell_type": "code", 176 | "execution_count": 11, 177 | "id": "6ee7e925", 178 | "metadata": {}, 179 | "outputs": [ 180 | { 181 | "data": { 182 | "text/plain": [ 183 | "6" 184 | ] 185 | }, 186 | "execution_count": 11, 187 | "metadata": {}, 188 | "output_type": "execute_result" 189 | } 190 | ], 191 | "source": [ 192 | "a.size" 193 | ] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": 12, 198 | "id": "12548006", 199 | "metadata": {}, 200 | "outputs": [ 201 | { 202 | "data": { 203 | "text/plain": [ 204 | "2" 205 | ] 206 | }, 207 | "execution_count": 12, 208 | "metadata": {}, 209 | "output_type": "execute_result" 210 | } 211 | ], 212 | "source": [ 213 | "a.ndim" 214 | ] 215 | }, 216 | { 217 | "cell_type": "code", 218 | "execution_count": 13, 219 | "id": "ede963a6", 220 | "metadata": {}, 221 | "outputs": [ 222 | { 223 | "data": { 224 | "text/plain": [ 225 | "dtype('int32')" 226 | ] 227 | }, 228 | "execution_count": 13, 229 | "metadata": {}, 230 | "output_type": "execute_result" 231 | } 232 | ], 233 | "source": [ 234 | "a.dtype" 235 | ] 236 | }, 237 | { 238 | "cell_type": "code", 239 | "execution_count": 22, 240 | "id": "6bf5d741", 241 | "metadata": {}, 242 | "outputs": [ 243 | { 244 | "name": "stdout", 245 | "output_type": "stream", 246 | "text": [ 247 | "10.142087936401367\n" 248 | ] 249 | } 250 | ], 251 | "source": [ 252 | "import time\n", 253 | "\n", 254 | "SIZE=100000\n", 255 | "L1=range(SIZE)\n", 256 | "L2=range(SIZE)\n", 257 | "\n", 258 | "A1=np.arange(SIZE)\n", 259 | "A2=np.arange(SIZE)\n", 260 | "\n", 261 | "start=time.time()\n", 262 | "result=[x+y for x,y in zip(L1,L2)]\n", 263 | "end=time.time()\n", 264 | "print((end-start)*1000)\n", 265 | "\n" 266 | ] 267 | }, 268 | { 269 | "cell_type": "code", 270 | "execution_count": 23, 271 | "id": "7711812e", 272 | "metadata": {}, 273 | "outputs": [ 274 | { 275 | "name": "stdout", 276 | "output_type": "stream", 277 | "text": [ 278 | "0.0\n" 279 | ] 280 | } 281 | ], 282 | "source": [ 283 | "start=time.time()\n", 284 | "res=A1+A2\n", 285 | "end=time.time()\n", 286 | "print((end-start)*1000)" 287 | ] 288 | }, 289 | { 290 | "cell_type": "code", 291 | "execution_count": 24, 292 | "id": "d6915947", 293 | "metadata": {}, 294 | "outputs": [], 295 | "source": [ 296 | "a=np.array([(1,2,3),(4,5,6),(7,8,9)])" 297 | ] 298 | }, 299 | { 300 | "cell_type": "code", 301 | "execution_count": 25, 302 | "id": "71022b46", 303 | "metadata": {}, 304 | "outputs": [ 305 | { 306 | "data": { 307 | "text/plain": [ 308 | "array([[1, 2, 3],\n", 309 | " [4, 5, 6],\n", 310 | " [7, 8, 9]])" 311 | ] 312 | }, 313 | "execution_count": 25, 314 | "metadata": {}, 315 | "output_type": "execute_result" 316 | } 317 | ], 318 | "source": [ 319 | "a" 320 | ] 321 | }, 322 | { 323 | "cell_type": "code", 324 | "execution_count": 26, 325 | "id": "55dadbe0", 326 | "metadata": {}, 327 | "outputs": [ 328 | { 329 | "data": { 330 | "text/plain": [ 331 | "(3, 3)" 332 | ] 333 | }, 334 | "execution_count": 26, 335 | "metadata": {}, 336 | "output_type": "execute_result" 337 | } 338 | ], 339 | "source": [ 340 | "a.shape" 341 | ] 342 | }, 343 | { 344 | "cell_type": "code", 345 | "execution_count": 27, 346 | "id": "d2650b2c", 347 | "metadata": {}, 348 | "outputs": [ 349 | { 350 | "name": "stdout", 351 | "output_type": "stream", 352 | "text": [ 353 | "[[1 2 3]\n", 354 | " [4 5 6]\n", 355 | " [7 8 9]]\n" 356 | ] 357 | } 358 | ], 359 | "source": [ 360 | "print(a)" 361 | ] 362 | }, 363 | { 364 | "cell_type": "code", 365 | "execution_count": 28, 366 | "id": "ec9bf043", 367 | "metadata": {}, 368 | "outputs": [ 369 | { 370 | "data": { 371 | "text/plain": [ 372 | "5" 373 | ] 374 | }, 375 | "execution_count": 28, 376 | "metadata": {}, 377 | "output_type": "execute_result" 378 | } 379 | ], 380 | "source": [ 381 | "a[1,1]" 382 | ] 383 | }, 384 | { 385 | "cell_type": "code", 386 | "execution_count": 29, 387 | "id": "8a944247", 388 | "metadata": {}, 389 | "outputs": [ 390 | { 391 | "data": { 392 | "text/plain": [ 393 | "array([[5, 6],\n", 394 | " [8, 9]])" 395 | ] 396 | }, 397 | "execution_count": 29, 398 | "metadata": {}, 399 | "output_type": "execute_result" 400 | } 401 | ], 402 | "source": [ 403 | "a[1:,1:]" 404 | ] 405 | }, 406 | { 407 | "cell_type": "code", 408 | "execution_count": 30, 409 | "id": "3761056d", 410 | "metadata": {}, 411 | "outputs": [ 412 | { 413 | "data": { 414 | "text/plain": [ 415 | "array([3, 6, 9])" 416 | ] 417 | }, 418 | "execution_count": 30, 419 | "metadata": {}, 420 | "output_type": "execute_result" 421 | } 422 | ], 423 | "source": [ 424 | "a[:,2]" 425 | ] 426 | }, 427 | { 428 | "cell_type": "code", 429 | "execution_count": 31, 430 | "id": "f53a84fe", 431 | "metadata": {}, 432 | "outputs": [], 433 | "source": [ 434 | "a=np.array([(1,2,3,4),(3,4,5,6),(7,8,9,10)])" 435 | ] 436 | }, 437 | { 438 | "cell_type": "code", 439 | "execution_count": 32, 440 | "id": "9ad04b26", 441 | "metadata": {}, 442 | "outputs": [ 443 | { 444 | "data": { 445 | "text/plain": [ 446 | "array([[ 1, 2, 3, 4],\n", 447 | " [ 3, 4, 5, 6],\n", 448 | " [ 7, 8, 9, 10]])" 449 | ] 450 | }, 451 | "execution_count": 32, 452 | "metadata": {}, 453 | "output_type": "execute_result" 454 | } 455 | ], 456 | "source": [ 457 | "a" 458 | ] 459 | }, 460 | { 461 | "cell_type": "code", 462 | "execution_count": 33, 463 | "id": "a55755c1", 464 | "metadata": {}, 465 | "outputs": [ 466 | { 467 | "data": { 468 | "text/plain": [ 469 | "(3, 4)" 470 | ] 471 | }, 472 | "execution_count": 33, 473 | "metadata": {}, 474 | "output_type": "execute_result" 475 | } 476 | ], 477 | "source": [ 478 | "a.shape" 479 | ] 480 | }, 481 | { 482 | "cell_type": "code", 483 | "execution_count": 34, 484 | "id": "149f3846", 485 | "metadata": {}, 486 | "outputs": [ 487 | { 488 | "data": { 489 | "text/plain": [ 490 | "array([[ 1, 2, 3],\n", 491 | " [ 4, 3, 4],\n", 492 | " [ 5, 6, 7],\n", 493 | " [ 8, 9, 10]])" 494 | ] 495 | }, 496 | "execution_count": 34, 497 | "metadata": {}, 498 | "output_type": "execute_result" 499 | } 500 | ], 501 | "source": [ 502 | "a.reshape(4,3)" 503 | ] 504 | }, 505 | { 506 | "cell_type": "code", 507 | "execution_count": 35, 508 | "id": "c2097b93", 509 | "metadata": {}, 510 | "outputs": [ 511 | { 512 | "data": { 513 | "text/plain": [ 514 | "array([[ 1, 2, 3, 4],\n", 515 | " [ 3, 4, 5, 6],\n", 516 | " [ 7, 8, 9, 10]])" 517 | ] 518 | }, 519 | "execution_count": 35, 520 | "metadata": {}, 521 | "output_type": "execute_result" 522 | } 523 | ], 524 | "source": [ 525 | "a" 526 | ] 527 | }, 528 | { 529 | "cell_type": "code", 530 | "execution_count": 36, 531 | "id": "e38b6825", 532 | "metadata": {}, 533 | "outputs": [ 534 | { 535 | "data": { 536 | "text/plain": [ 537 | "array([4, 6])" 538 | ] 539 | }, 540 | "execution_count": 36, 541 | "metadata": {}, 542 | "output_type": "execute_result" 543 | } 544 | ], 545 | "source": [ 546 | "a[0:2,3]" 547 | ] 548 | }, 549 | { 550 | "cell_type": "code", 551 | "execution_count": 37, 552 | "id": "06884944", 553 | "metadata": {}, 554 | "outputs": [ 555 | { 556 | "data": { 557 | "text/plain": [ 558 | "1" 559 | ] 560 | }, 561 | "execution_count": 37, 562 | "metadata": {}, 563 | "output_type": "execute_result" 564 | } 565 | ], 566 | "source": [ 567 | "a.min()" 568 | ] 569 | }, 570 | { 571 | "cell_type": "code", 572 | "execution_count": 38, 573 | "id": "ac08a027", 574 | "metadata": {}, 575 | "outputs": [ 576 | { 577 | "data": { 578 | "text/plain": [ 579 | "10" 580 | ] 581 | }, 582 | "execution_count": 38, 583 | "metadata": {}, 584 | "output_type": "execute_result" 585 | } 586 | ], 587 | "source": [ 588 | "a.max()" 589 | ] 590 | }, 591 | { 592 | "cell_type": "code", 593 | "execution_count": 39, 594 | "id": "a0ea163b", 595 | "metadata": {}, 596 | "outputs": [ 597 | { 598 | "data": { 599 | "text/plain": [ 600 | "62" 601 | ] 602 | }, 603 | "execution_count": 39, 604 | "metadata": {}, 605 | "output_type": "execute_result" 606 | } 607 | ], 608 | "source": [ 609 | "a.sum()" 610 | ] 611 | }, 612 | { 613 | "cell_type": "code", 614 | "execution_count": 40, 615 | "id": "8289c9e2", 616 | "metadata": {}, 617 | "outputs": [ 618 | { 619 | "data": { 620 | "text/plain": [ 621 | "array([[ 1, 2, 3, 4],\n", 622 | " [ 3, 4, 5, 6],\n", 623 | " [ 7, 8, 9, 10]])" 624 | ] 625 | }, 626 | "execution_count": 40, 627 | "metadata": {}, 628 | "output_type": "execute_result" 629 | } 630 | ], 631 | "source": [ 632 | "a" 633 | ] 634 | }, 635 | { 636 | "cell_type": "code", 637 | "execution_count": 41, 638 | "id": "523254e5", 639 | "metadata": {}, 640 | "outputs": [ 641 | { 642 | "data": { 643 | "text/plain": [ 644 | "array([11, 14, 17, 20])" 645 | ] 646 | }, 647 | "execution_count": 41, 648 | "metadata": {}, 649 | "output_type": "execute_result" 650 | } 651 | ], 652 | "source": [ 653 | "a.sum(axis=0)" 654 | ] 655 | }, 656 | { 657 | "cell_type": "code", 658 | "execution_count": 42, 659 | "id": "f39502a2", 660 | "metadata": {}, 661 | "outputs": [ 662 | { 663 | "data": { 664 | "text/plain": [ 665 | "array([10, 18, 34])" 666 | ] 667 | }, 668 | "execution_count": 42, 669 | "metadata": {}, 670 | "output_type": "execute_result" 671 | } 672 | ], 673 | "source": [ 674 | "a.sum(axis=1)" 675 | ] 676 | }, 677 | { 678 | "cell_type": "code", 679 | "execution_count": 43, 680 | "id": "da1dfce5", 681 | "metadata": {}, 682 | "outputs": [ 683 | { 684 | "data": { 685 | "text/plain": [ 686 | "array([[1. , 1.41421356, 1.73205081, 2. ],\n", 687 | " [1.73205081, 2. , 2.23606798, 2.44948974],\n", 688 | " [2.64575131, 2.82842712, 3. , 3.16227766]])" 689 | ] 690 | }, 691 | "execution_count": 43, 692 | "metadata": {}, 693 | "output_type": "execute_result" 694 | } 695 | ], 696 | "source": [ 697 | "np.sqrt(a)" 698 | ] 699 | }, 700 | { 701 | "cell_type": "code", 702 | "execution_count": 44, 703 | "id": "07a337d1", 704 | "metadata": {}, 705 | "outputs": [ 706 | { 707 | "data": { 708 | "text/plain": [ 709 | "2.733536577809454" 710 | ] 711 | }, 712 | "execution_count": 44, 713 | "metadata": {}, 714 | "output_type": "execute_result" 715 | } 716 | ], 717 | "source": [ 718 | "np.std(a)" 719 | ] 720 | }, 721 | { 722 | "cell_type": "code", 723 | "execution_count": 54, 724 | "id": "44df75d1", 725 | "metadata": {}, 726 | "outputs": [], 727 | "source": [ 728 | "a=np.array([(1,2,3),(4,5,6)])\n", 729 | "b=np.array([(1,2,3),(4,5,6)])" 730 | ] 731 | }, 732 | { 733 | "cell_type": "code", 734 | "execution_count": 46, 735 | "id": "a2ed0ebe", 736 | "metadata": {}, 737 | "outputs": [ 738 | { 739 | "data": { 740 | "text/plain": [ 741 | "array([[1, 2, 3],\n", 742 | " [4, 5, 6]])" 743 | ] 744 | }, 745 | "execution_count": 46, 746 | "metadata": {}, 747 | "output_type": "execute_result" 748 | } 749 | ], 750 | "source": [ 751 | "a" 752 | ] 753 | }, 754 | { 755 | "cell_type": "code", 756 | "execution_count": 47, 757 | "id": "da6a05a6", 758 | "metadata": {}, 759 | "outputs": [ 760 | { 761 | "data": { 762 | "text/plain": [ 763 | "array([[ 2, 4, 6],\n", 764 | " [ 8, 10, 12]])" 765 | ] 766 | }, 767 | "execution_count": 47, 768 | "metadata": {}, 769 | "output_type": "execute_result" 770 | } 771 | ], 772 | "source": [ 773 | "a+b" 774 | ] 775 | }, 776 | { 777 | "cell_type": "code", 778 | "execution_count": 48, 779 | "id": "94aa5bcd", 780 | "metadata": {}, 781 | "outputs": [ 782 | { 783 | "data": { 784 | "text/plain": [ 785 | "array([[0, 0, 0],\n", 786 | " [0, 0, 0]])" 787 | ] 788 | }, 789 | "execution_count": 48, 790 | "metadata": {}, 791 | "output_type": "execute_result" 792 | } 793 | ], 794 | "source": [ 795 | "a-b" 796 | ] 797 | }, 798 | { 799 | "cell_type": "code", 800 | "execution_count": 49, 801 | "id": "8ca4c599", 802 | "metadata": {}, 803 | "outputs": [ 804 | { 805 | "data": { 806 | "text/plain": [ 807 | "array([[ 1, 4, 9],\n", 808 | " [16, 25, 36]])" 809 | ] 810 | }, 811 | "execution_count": 49, 812 | "metadata": {}, 813 | "output_type": "execute_result" 814 | } 815 | ], 816 | "source": [ 817 | "a*b" 818 | ] 819 | }, 820 | { 821 | "cell_type": "code", 822 | "execution_count": 55, 823 | "id": "56462342", 824 | "metadata": {}, 825 | "outputs": [ 826 | { 827 | "ename": "ValueError", 828 | "evalue": "shapes (2,3) and (2,3) not aligned: 3 (dim 1) != 2 (dim 0)", 829 | "output_type": "error", 830 | "traceback": [ 831 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 832 | "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", 833 | "Input \u001b[1;32mIn [55]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mnp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdot\u001b[49m\u001b[43m(\u001b[49m\u001b[43ma\u001b[49m\u001b[43m,\u001b[49m\u001b[43mb\u001b[49m\u001b[43m)\u001b[49m\n", 834 | "File \u001b[1;32m<__array_function__ internals>:180\u001b[0m, in \u001b[0;36mdot\u001b[1;34m(*args, **kwargs)\u001b[0m\n", 835 | "\u001b[1;31mValueError\u001b[0m: shapes (2,3) and (2,3) not aligned: 3 (dim 1) != 2 (dim 0)" 836 | ] 837 | } 838 | ], 839 | "source": [ 840 | "np.dot(a,b)" 841 | ] 842 | }, 843 | { 844 | "cell_type": "code", 845 | "execution_count": 56, 846 | "id": "30a518ec", 847 | "metadata": {}, 848 | "outputs": [], 849 | "source": [ 850 | "a=np.array([(1,2,3),(4,5,6),(7,8,9)])\n", 851 | "b=np.array([(1,2,3),(4,5,6),(7,8,9)])" 852 | ] 853 | }, 854 | { 855 | "cell_type": "code", 856 | "execution_count": 59, 857 | "id": "921f1a8a", 858 | "metadata": {}, 859 | "outputs": [ 860 | { 861 | "data": { 862 | "text/plain": [ 863 | "array([[ 30, 36, 42],\n", 864 | " [ 66, 81, 96],\n", 865 | " [102, 126, 150]])" 866 | ] 867 | }, 868 | "execution_count": 59, 869 | "metadata": {}, 870 | "output_type": "execute_result" 871 | } 872 | ], 873 | "source": [ 874 | "np.dot(a,b)" 875 | ] 876 | }, 877 | { 878 | "cell_type": "code", 879 | "execution_count": 61, 880 | "id": "4fb5fe41", 881 | "metadata": {}, 882 | "outputs": [ 883 | { 884 | "data": { 885 | "text/plain": [ 886 | "array([[1, 2, 3, 1, 2, 3],\n", 887 | " [4, 5, 6, 4, 5, 6],\n", 888 | " [7, 8, 9, 7, 8, 9]])" 889 | ] 890 | }, 891 | "execution_count": 61, 892 | "metadata": {}, 893 | "output_type": "execute_result" 894 | } 895 | ], 896 | "source": [ 897 | "np.hstack((a,b))" 898 | ] 899 | }, 900 | { 901 | "cell_type": "code", 902 | "execution_count": 62, 903 | "id": "93a58be8", 904 | "metadata": {}, 905 | "outputs": [ 906 | { 907 | "data": { 908 | "text/plain": [ 909 | "array([[1, 2, 3],\n", 910 | " [4, 5, 6],\n", 911 | " [7, 8, 9],\n", 912 | " [1, 2, 3],\n", 913 | " [4, 5, 6],\n", 914 | " [7, 8, 9]])" 915 | ] 916 | }, 917 | "execution_count": 62, 918 | "metadata": {}, 919 | "output_type": "execute_result" 920 | } 921 | ], 922 | "source": [ 923 | "np.vstack((a,b))" 924 | ] 925 | }, 926 | { 927 | "cell_type": "code", 928 | "execution_count": 63, 929 | "id": "5af1ea50", 930 | "metadata": {}, 931 | "outputs": [ 932 | { 933 | "data": { 934 | "text/plain": [ 935 | "array([[1, 2, 3],\n", 936 | " [4, 5, 6],\n", 937 | " [7, 8, 9]])" 938 | ] 939 | }, 940 | "execution_count": 63, 941 | "metadata": {}, 942 | "output_type": "execute_result" 943 | } 944 | ], 945 | "source": [ 946 | "a" 947 | ] 948 | }, 949 | { 950 | "cell_type": "code", 951 | "execution_count": 64, 952 | "id": "30b64d68", 953 | "metadata": {}, 954 | "outputs": [ 955 | { 956 | "data": { 957 | "text/plain": [ 958 | "array([1, 2, 3, 4, 5, 6, 7, 8, 9])" 959 | ] 960 | }, 961 | "execution_count": 64, 962 | "metadata": {}, 963 | "output_type": "execute_result" 964 | } 965 | ], 966 | "source": [ 967 | "a.ravel()" 968 | ] 969 | }, 970 | { 971 | "cell_type": "code", 972 | "execution_count": 65, 973 | "id": "db9f6e06", 974 | "metadata": {}, 975 | "outputs": [ 976 | { 977 | "data": { 978 | "text/plain": [ 979 | "array([[0. , 0.69314718, 1.09861229],\n", 980 | " [1.38629436, 1.60943791, 1.79175947],\n", 981 | " [1.94591015, 2.07944154, 2.19722458]])" 982 | ] 983 | }, 984 | "execution_count": 65, 985 | "metadata": {}, 986 | "output_type": "execute_result" 987 | } 988 | ], 989 | "source": [ 990 | "np.log(a)" 991 | ] 992 | }, 993 | { 994 | "cell_type": "code", 995 | "execution_count": 66, 996 | "id": "ee3bb11f", 997 | "metadata": {}, 998 | "outputs": [ 999 | { 1000 | "data": { 1001 | "text/plain": [ 1002 | "array([[2.71828183e+00, 7.38905610e+00, 2.00855369e+01],\n", 1003 | " [5.45981500e+01, 1.48413159e+02, 4.03428793e+02],\n", 1004 | " [1.09663316e+03, 2.98095799e+03, 8.10308393e+03]])" 1005 | ] 1006 | }, 1007 | "execution_count": 66, 1008 | "metadata": {}, 1009 | "output_type": "execute_result" 1010 | } 1011 | ], 1012 | "source": [ 1013 | "np.exp(a)" 1014 | ] 1015 | }, 1016 | { 1017 | "cell_type": "code", 1018 | "execution_count": 68, 1019 | "id": "1d1d40be", 1020 | "metadata": {}, 1021 | "outputs": [ 1022 | { 1023 | "data": { 1024 | "text/plain": [ 1025 | "array([[0., 0., 0.],\n", 1026 | " [0., 0., 0.],\n", 1027 | " [0., 0., 0.]])" 1028 | ] 1029 | }, 1030 | "execution_count": 68, 1031 | "metadata": {}, 1032 | "output_type": "execute_result" 1033 | } 1034 | ], 1035 | "source": [ 1036 | "np.zeros((3,3))" 1037 | ] 1038 | }, 1039 | { 1040 | "cell_type": "code", 1041 | "execution_count": 69, 1042 | "id": "aa5c2438", 1043 | "metadata": {}, 1044 | "outputs": [ 1045 | { 1046 | "data": { 1047 | "text/plain": [ 1048 | "array([[1., 1., 1.],\n", 1049 | " [1., 1., 1.],\n", 1050 | " [1., 1., 1.]])" 1051 | ] 1052 | }, 1053 | "execution_count": 69, 1054 | "metadata": {}, 1055 | "output_type": "execute_result" 1056 | } 1057 | ], 1058 | "source": [ 1059 | "np.ones((3,3))" 1060 | ] 1061 | }, 1062 | { 1063 | "cell_type": "code", 1064 | "execution_count": 70, 1065 | "id": "d92213ed", 1066 | "metadata": {}, 1067 | "outputs": [ 1068 | { 1069 | "data": { 1070 | "text/plain": [ 1071 | "array([[99, 99, 99],\n", 1072 | " [99, 99, 99],\n", 1073 | " [99, 99, 99]])" 1074 | ] 1075 | }, 1076 | "execution_count": 70, 1077 | "metadata": {}, 1078 | "output_type": "execute_result" 1079 | } 1080 | ], 1081 | "source": [ 1082 | "np.full((3,3),99)" 1083 | ] 1084 | }, 1085 | { 1086 | "cell_type": "code", 1087 | "execution_count": 71, 1088 | "id": "c05477b7", 1089 | "metadata": {}, 1090 | "outputs": [ 1091 | { 1092 | "data": { 1093 | "text/plain": [ 1094 | "array([[1., 0., 0., 0., 0.],\n", 1095 | " [0., 1., 0., 0., 0.],\n", 1096 | " [0., 0., 1., 0., 0.],\n", 1097 | " [0., 0., 0., 1., 0.],\n", 1098 | " [0., 0., 0., 0., 1.]])" 1099 | ] 1100 | }, 1101 | "execution_count": 71, 1102 | "metadata": {}, 1103 | "output_type": "execute_result" 1104 | } 1105 | ], 1106 | "source": [ 1107 | "np.identity(5)" 1108 | ] 1109 | }, 1110 | { 1111 | "cell_type": "code", 1112 | "execution_count": null, 1113 | "id": "153cd35f", 1114 | "metadata": {}, 1115 | "outputs": [], 1116 | "source": [] 1117 | } 1118 | ], 1119 | "metadata": { 1120 | "kernelspec": { 1121 | "display_name": "Python 3 (ipykernel)", 1122 | "language": "python", 1123 | "name": "python3" 1124 | }, 1125 | "language_info": { 1126 | "codemirror_mode": { 1127 | "name": "ipython", 1128 | "version": 3 1129 | }, 1130 | "file_extension": ".py", 1131 | "mimetype": "text/x-python", 1132 | "name": "python", 1133 | "nbconvert_exporter": "python", 1134 | "pygments_lexer": "ipython3", 1135 | "version": "3.8.10" 1136 | } 1137 | }, 1138 | "nbformat": 4, 1139 | "nbformat_minor": 5 1140 | } 1141 | -------------------------------------------------------------------------------- /oops_abstraction.py: -------------------------------------------------------------------------------- 1 | from abc import ABC , abstractmethod 2 | class Car(ABC): 3 | @abstractmethod 4 | def breaks(self): 5 | pass 6 | @abstractmethod 7 | def seats(self): 8 | pass 9 | @abstractmethod 10 | def engine(self): 11 | pass 12 | @abstractmethod 13 | def tyres(self): 14 | pass 15 | def price(self): 16 | return "{}".format(1600000) 17 | 18 | class EcoSport(Car): 19 | def __init__(self,make,model): 20 | self.make=make 21 | self.model=model 22 | def breaks(self): 23 | self.break_applied="Yes" 24 | def seats(self): 25 | self.count="10 seater" 26 | def engine(self): 27 | self.engine_type="Petrol engine" 28 | def tyres(self): 29 | self.tire="fitted" 30 | def order(self,cust_name,deposit): 31 | self.cust_name=cust_name 32 | self.deposit=deposit 33 | self.delivery_date="25-08-2022" 34 | c1=EcoSport(2022,"Ford") 35 | 36 | print(c1.price()) 37 | c1.order('Raghul Ramesh',20000) 38 | print(c1.delivery_date) -------------------------------------------------------------------------------- /oops_encap.py: -------------------------------------------------------------------------------- 1 | class Account(): 2 | def __init__(self,fname,lname,deposit): 3 | self.fname=fname 4 | self.lname=lname 5 | self.__amount=deposit #protected(_) private(__) public 6 | self.username="{}{}".format(self.fname,123) 7 | self.password="{}{}".format(self.fname.title(),'#100') 8 | 9 | def setAmount(self,amt): 10 | self.__amount=self.__amount+amt 11 | 12 | def getAmount(self): 13 | return self.__amount 14 | -------------------------------------------------------------------------------- /oops_encap_user4.py: -------------------------------------------------------------------------------- 1 | from oops_encap import Account 2 | 3 | acc_1=Account('Raghul','Ramesh',10000) 4 | 5 | print(acc_1.getAmount()) 6 | acc_1.setAmount(10000) 7 | print(acc_1.getAmount()) 8 | 9 | 10 | -------------------------------------------------------------------------------- /oops_inheritance.py: -------------------------------------------------------------------------------- 1 | class Employee(): 2 | #hike=1.1 3 | def __init__(self,fname,lname,pay): #constructor 4 | self.fname=fname 5 | self.lname=lname 6 | self.salary=pay 7 | self.email=self.fname+'.'+self.lname+'@gmail.com' 8 | 9 | def fullname(self): 10 | return "{}.{}".format(self.fname,self.lname) 11 | 12 | def appraisal(self): 13 | self.hike=2 14 | #print("Hike for the year is : ", self.hike) 15 | self.salary = int(self.salary*self.hike) 16 | 17 | @classmethod 18 | def emp_object(cls,emp_str): 19 | fn,ln,sal=emp_str.split('-') 20 | return cls(fn,ln,int(sal)) #Employee(fn,ln,sal) 21 | 22 | @staticmethod 23 | def is_workingday(day): 24 | if day.weekday() == 5 or day.weekday() == 6: 25 | return "Holiday!" 26 | else: 27 | return "Working Day!" 28 | class Manager(): 29 | def info(self): 30 | print("Data Analytics - Python - MySQL") 31 | 32 | def appraisal(self): 33 | self.hike=3 34 | #print("Hike for the year is : ", self.hike) 35 | self.salary = int(self.salary*self.hike) 36 | 37 | class Developer(Employee,Manager): 38 | def __init__(self,fname,lname,pay,tech): 39 | self.tech=tech 40 | super().__init__(fname,lname,pay) 41 | 42 | def add_nums(self,*args): 43 | return sum(args) 44 | 45 | def fullname(self,title): 46 | return "{}.{} {}".format(title,self.fname,self.lname) 47 | 48 | def appraisal(self): 49 | super(Employee,self).appraisal() 50 | #Manager().appraisal(self) 51 | 52 | dev_1=Developer('Siva','Murugan',100000,'Python') 53 | dev_2=Developer('Ramya','Karthick',150000,'AIML') 54 | print(dev_1.email) 55 | print(dev_1.add_nums(1,2,3,4,5,6,7,8,9,10)) 56 | print(dev_1.fullname('Mr')) 57 | print(dev_2.fullname('Mrs')) 58 | dev_1.info() 59 | 60 | print(dev_1.salary) 61 | dev_1.appraisal() 62 | print(dev_1.salary) 63 | 64 | #print(help(dev_1)) 65 | # Method Overloading is not needed in python 66 | #overriding 67 | #Overloading : two method in the same name in a class is called overloading. both method varies in 68 | #number of arguments or type of the arguments 69 | 70 | #overriding : in a parent-child classes, if we redefine the method in child class which exists in 71 | #parent class is called overriding -------------------------------------------------------------------------------- /set.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "id": "6b39ee06", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "odds={1,3,5,7,9}\n", 11 | "even={2,4,6,8,10}\n", 12 | "prime={1,3,5,7}\n", 13 | "composites={1,2,4,5,6,8,9}" 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": 2, 19 | "id": "0de4d92b", 20 | "metadata": {}, 21 | "outputs": [ 22 | { 23 | "data": { 24 | "text/plain": [ 25 | "{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}" 26 | ] 27 | }, 28 | "execution_count": 2, 29 | "metadata": {}, 30 | "output_type": "execute_result" 31 | } 32 | ], 33 | "source": [ 34 | "odds.union(even)" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": 3, 40 | "id": "605bc2d4", 41 | "metadata": {}, 42 | "outputs": [ 43 | { 44 | "data": { 45 | "text/plain": [ 46 | "{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}" 47 | ] 48 | }, 49 | "execution_count": 3, 50 | "metadata": {}, 51 | "output_type": "execute_result" 52 | } 53 | ], 54 | "source": [ 55 | "even.union(odds)" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": 4, 61 | "id": "e97fba14", 62 | "metadata": {}, 63 | "outputs": [ 64 | { 65 | "data": { 66 | "text/plain": [ 67 | "set()" 68 | ] 69 | }, 70 | "execution_count": 4, 71 | "metadata": {}, 72 | "output_type": "execute_result" 73 | } 74 | ], 75 | "source": [ 76 | "odds.intersection(even)" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 5, 82 | "id": "0bfee494", 83 | "metadata": {}, 84 | "outputs": [ 85 | { 86 | "data": { 87 | "text/plain": [ 88 | "{1, 5, 9}" 89 | ] 90 | }, 91 | "execution_count": 5, 92 | "metadata": {}, 93 | "output_type": "execute_result" 94 | } 95 | ], 96 | "source": [ 97 | "odds.intersection(composites)" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": 6, 103 | "id": "cfb9eb28", 104 | "metadata": {}, 105 | "outputs": [ 106 | { 107 | "data": { 108 | "text/plain": [ 109 | "{3, 7}" 110 | ] 111 | }, 112 | "execution_count": 6, 113 | "metadata": {}, 114 | "output_type": "execute_result" 115 | } 116 | ], 117 | "source": [ 118 | "odds.difference(composites)" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": 7, 124 | "id": "3712aa14", 125 | "metadata": {}, 126 | "outputs": [ 127 | { 128 | "data": { 129 | "text/plain": [ 130 | "{2, 4, 6, 8}" 131 | ] 132 | }, 133 | "execution_count": 7, 134 | "metadata": {}, 135 | "output_type": "execute_result" 136 | } 137 | ], 138 | "source": [ 139 | "composites.difference(odds)" 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": 9, 145 | "id": "2c6d7cc8", 146 | "metadata": {}, 147 | "outputs": [], 148 | "source": [ 149 | "a={1,3,5,7,9}\n", 150 | "b={1,2,4,5,6,8,9}" 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "execution_count": 10, 156 | "id": "0aa42abf", 157 | "metadata": {}, 158 | "outputs": [ 159 | { 160 | "data": { 161 | "text/plain": [ 162 | "{3, 7}" 163 | ] 164 | }, 165 | "execution_count": 10, 166 | "metadata": {}, 167 | "output_type": "execute_result" 168 | } 169 | ], 170 | "source": [ 171 | "a-b" 172 | ] 173 | }, 174 | { 175 | "cell_type": "code", 176 | "execution_count": 11, 177 | "id": "13f1fb7e", 178 | "metadata": {}, 179 | "outputs": [ 180 | { 181 | "data": { 182 | "text/plain": [ 183 | "{2, 4, 6, 8}" 184 | ] 185 | }, 186 | "execution_count": 11, 187 | "metadata": {}, 188 | "output_type": "execute_result" 189 | } 190 | ], 191 | "source": [ 192 | "b-a" 193 | ] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": 12, 198 | "id": "909b277c", 199 | "metadata": {}, 200 | "outputs": [ 201 | { 202 | "data": { 203 | "text/plain": [ 204 | "{1, 5, 9}" 205 | ] 206 | }, 207 | "execution_count": 12, 208 | "metadata": {}, 209 | "output_type": "execute_result" 210 | } 211 | ], 212 | "source": [ 213 | "a&b" 214 | ] 215 | }, 216 | { 217 | "cell_type": "code", 218 | "execution_count": 14, 219 | "id": "8a38b303", 220 | "metadata": {}, 221 | "outputs": [ 222 | { 223 | "data": { 224 | "text/plain": [ 225 | "{2, 3, 4, 6, 7, 8}" 226 | ] 227 | }, 228 | "execution_count": 14, 229 | "metadata": {}, 230 | "output_type": "execute_result" 231 | } 232 | ], 233 | "source": [ 234 | "(a-b).union(b-a)" 235 | ] 236 | }, 237 | { 238 | "cell_type": "code", 239 | "execution_count": 15, 240 | "id": "274de3d3", 241 | "metadata": {}, 242 | "outputs": [ 243 | { 244 | "data": { 245 | "text/plain": [ 246 | "{2, 3, 4, 6, 7, 8}" 247 | ] 248 | }, 249 | "execution_count": 15, 250 | "metadata": {}, 251 | "output_type": "execute_result" 252 | } 253 | ], 254 | "source": [ 255 | "a.symmetric_difference(b)" 256 | ] 257 | }, 258 | { 259 | "cell_type": "code", 260 | "execution_count": 16, 261 | "id": "c3c695b0", 262 | "metadata": {}, 263 | "outputs": [ 264 | { 265 | "data": { 266 | "text/plain": [ 267 | "{2, 3, 4, 6, 7, 8}" 268 | ] 269 | }, 270 | "execution_count": 16, 271 | "metadata": {}, 272 | "output_type": "execute_result" 273 | } 274 | ], 275 | "source": [ 276 | "a^b" 277 | ] 278 | }, 279 | { 280 | "cell_type": "code", 281 | "execution_count": 17, 282 | "id": "0499de53", 283 | "metadata": {}, 284 | "outputs": [], 285 | "source": [ 286 | "mydata=[1,3,5,2,1,3,5,5,6,4,3,2,5,6,7,8,8,9,0,8,6,5,4,1]" 287 | ] 288 | }, 289 | { 290 | "cell_type": "code", 291 | "execution_count": 18, 292 | "id": "fd1a54eb", 293 | "metadata": {}, 294 | "outputs": [ 295 | { 296 | "data": { 297 | "text/plain": [ 298 | "[1, 3, 5, 2, 1, 3, 5, 5, 6, 4, 3, 2, 5, 6, 7, 8, 8, 9, 0, 8, 6, 5, 4, 1]" 299 | ] 300 | }, 301 | "execution_count": 18, 302 | "metadata": {}, 303 | "output_type": "execute_result" 304 | } 305 | ], 306 | "source": [ 307 | "mydata" 308 | ] 309 | }, 310 | { 311 | "cell_type": "code", 312 | "execution_count": 20, 313 | "id": "fdf45f2f", 314 | "metadata": {}, 315 | "outputs": [], 316 | "source": [ 317 | "mydata1=list(set(mydata))" 318 | ] 319 | }, 320 | { 321 | "cell_type": "code", 322 | "execution_count": 21, 323 | "id": "8baa7707", 324 | "metadata": {}, 325 | "outputs": [ 326 | { 327 | "data": { 328 | "text/plain": [ 329 | "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]" 330 | ] 331 | }, 332 | "execution_count": 21, 333 | "metadata": {}, 334 | "output_type": "execute_result" 335 | } 336 | ], 337 | "source": [ 338 | "mydata1" 339 | ] 340 | }, 341 | { 342 | "cell_type": "code", 343 | "execution_count": null, 344 | "id": "4b83cbc1", 345 | "metadata": {}, 346 | "outputs": [], 347 | "source": [ 348 | "immutable\n", 349 | " Numbers\n", 350 | " Strings\n", 351 | " Tuples\n", 352 | "Mutable\n", 353 | " List\n", 354 | " Dictonary\n", 355 | " Set" 356 | ] 357 | }, 358 | { 359 | "cell_type": "code", 360 | "execution_count": null, 361 | "id": "0bbdc8a7", 362 | "metadata": {}, 363 | "outputs": [], 364 | "source": [ 365 | "#List Comprehension\n", 366 | "[ expr for x in collection/sequence]\n", 367 | "[ expr for x in collection/sequence if cond]\n", 368 | "[ expr for x in collection/sequence if cond1 & cond2]\n", 369 | "[ expr for x in collection/sequence for y in collection/sequence]" 370 | ] 371 | }, 372 | { 373 | "cell_type": "code", 374 | "execution_count": 22, 375 | "id": "88224ae0", 376 | "metadata": {}, 377 | "outputs": [ 378 | { 379 | "data": { 380 | "text/plain": [ 381 | "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]" 382 | ] 383 | }, 384 | "execution_count": 22, 385 | "metadata": {}, 386 | "output_type": "execute_result" 387 | } 388 | ], 389 | "source": [ 390 | "list(range(1,11))" 391 | ] 392 | }, 393 | { 394 | "cell_type": "code", 395 | "execution_count": 23, 396 | "id": "47d83c91", 397 | "metadata": {}, 398 | "outputs": [ 399 | { 400 | "data": { 401 | "text/plain": [ 402 | "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]" 403 | ] 404 | }, 405 | "execution_count": 23, 406 | "metadata": {}, 407 | "output_type": "execute_result" 408 | } 409 | ], 410 | "source": [ 411 | "[ x**2 for x in range(1,11)]" 412 | ] 413 | }, 414 | { 415 | "cell_type": "code", 416 | "execution_count": 25, 417 | "id": "eea94368", 418 | "metadata": {}, 419 | "outputs": [ 420 | { 421 | "data": { 422 | "text/plain": [ 423 | "[1, 3, 5, 7, 9]" 424 | ] 425 | }, 426 | "execution_count": 25, 427 | "metadata": {}, 428 | "output_type": "execute_result" 429 | } 430 | ], 431 | "source": [ 432 | "[ x for x in range(1,11) if x%2==1]" 433 | ] 434 | }, 435 | { 436 | "cell_type": "code", 437 | "execution_count": 26, 438 | "id": "46ea4b28", 439 | "metadata": {}, 440 | "outputs": [ 441 | { 442 | "data": { 443 | "text/plain": [ 444 | "[2, 4, 6, 8, 10]" 445 | ] 446 | }, 447 | "execution_count": 26, 448 | "metadata": {}, 449 | "output_type": "execute_result" 450 | } 451 | ], 452 | "source": [ 453 | "[ x for x in range(1,11) if x%2==0]" 454 | ] 455 | }, 456 | { 457 | "cell_type": "code", 458 | "execution_count": 27, 459 | "id": "29a0483b", 460 | "metadata": {}, 461 | "outputs": [ 462 | { 463 | "data": { 464 | "text/plain": [ 465 | "[7, 9]" 466 | ] 467 | }, 468 | "execution_count": 27, 469 | "metadata": {}, 470 | "output_type": "execute_result" 471 | } 472 | ], 473 | "source": [ 474 | "[ x for x in range(1,11) if x%2==1 and x>5]" 475 | ] 476 | }, 477 | { 478 | "cell_type": "code", 479 | "execution_count": 28, 480 | "id": "bf9c7089", 481 | "metadata": {}, 482 | "outputs": [ 483 | { 484 | "data": { 485 | "text/plain": [ 486 | "[78.5, 113.04, 28.26, 153.86, 615.44, 706.5, 452.16, 379.94, 803.84]" 487 | ] 488 | }, 489 | "execution_count": 28, 490 | "metadata": {}, 491 | "output_type": "execute_result" 492 | } 493 | ], 494 | "source": [ 495 | "#calc the circle's area : 3.14*r**2\n", 496 | "\n", 497 | "radius=[5,6,3,7,14,15,12,11,16]\n", 498 | "[3.14*r**2 for r in radius]" 499 | ] 500 | }, 501 | { 502 | "cell_type": "code", 503 | "execution_count": 29, 504 | "id": "821ceed4", 505 | "metadata": {}, 506 | "outputs": [ 507 | { 508 | "data": { 509 | "text/plain": [ 510 | "[(1, 6),\n", 511 | " (1, 7),\n", 512 | " (1, 8),\n", 513 | " (1, 9),\n", 514 | " (1, 10),\n", 515 | " (2, 6),\n", 516 | " (2, 7),\n", 517 | " (2, 8),\n", 518 | " (2, 9),\n", 519 | " (2, 10),\n", 520 | " (3, 6),\n", 521 | " (3, 7),\n", 522 | " (3, 8),\n", 523 | " (3, 9),\n", 524 | " (3, 10),\n", 525 | " (4, 6),\n", 526 | " (4, 7),\n", 527 | " (4, 8),\n", 528 | " (4, 9),\n", 529 | " (4, 10),\n", 530 | " (5, 6),\n", 531 | " (5, 7),\n", 532 | " (5, 8),\n", 533 | " (5, 9),\n", 534 | " (5, 10)]" 535 | ] 536 | }, 537 | "execution_count": 29, 538 | "metadata": {}, 539 | "output_type": "execute_result" 540 | } 541 | ], 542 | "source": [ 543 | "x=[1,2,3,4,5]\n", 544 | "y=[6,7,8,9,10]\n", 545 | "\n", 546 | "[(a,b) for a in x for b in y]\n" 547 | ] 548 | }, 549 | { 550 | "cell_type": "code", 551 | "execution_count": 38, 552 | "id": "296ef944", 553 | "metadata": {}, 554 | "outputs": [ 555 | { 556 | "data": { 557 | "text/plain": [ 558 | "[45.25, 64.25, 87.25, 114.25, 145.25]" 559 | ] 560 | }, 561 | "execution_count": 38, 562 | "metadata": {}, 563 | "output_type": "execute_result" 564 | } 565 | ], 566 | "source": [ 567 | "x=[1.5,2.5,3.5,4.5,5.5]\n", 568 | "y=[6,7,8,9,10]\n", 569 | "r=[7,9,11,13,15]\n", 570 | "\n", 571 | "[a**2+b**2+c for a,b,c in zip(x,y,r)]" 572 | ] 573 | }, 574 | { 575 | "cell_type": "code", 576 | "execution_count": 40, 577 | "id": "eb8f6ee8", 578 | "metadata": {}, 579 | "outputs": [], 580 | "source": [ 581 | "employees={'Chandra','Aveek','Pankaj','Shyam','Jitendra','Rishabh','Mahima','Ramya'}\n", 582 | "developers={'Chandra','Aveek','Pankaj','Shyam'}\n", 583 | "Managers={'Mahima','Rishabh'}\n", 584 | "gym_users={'Chandra','Aveek','Rishabh','Ramya'}\n", 585 | "\n", 586 | "# 1. Get me the list of the employees who are not a developer, manager but member of gym_user\n", 587 | "# 2. Get me the list of employees who are not a manager or developer\n", 588 | "# 3. Get me the list of employees who are using gym being as a manager" 589 | ] 590 | }, 591 | { 592 | "cell_type": "code", 593 | "execution_count": 43, 594 | "id": "036abbc7", 595 | "metadata": {}, 596 | "outputs": [ 597 | { 598 | "data": { 599 | "text/plain": [ 600 | "{'Ramya'}" 601 | ] 602 | }, 603 | "execution_count": 43, 604 | "metadata": {}, 605 | "output_type": "execute_result" 606 | } 607 | ], 608 | "source": [ 609 | "gym_users-(developers.union(Managers))" 610 | ] 611 | }, 612 | { 613 | "cell_type": "code", 614 | "execution_count": 44, 615 | "id": "01e72225", 616 | "metadata": {}, 617 | "outputs": [ 618 | { 619 | "data": { 620 | "text/plain": [ 621 | "{'Jitendra', 'Ramya'}" 622 | ] 623 | }, 624 | "execution_count": 44, 625 | "metadata": {}, 626 | "output_type": "execute_result" 627 | } 628 | ], 629 | "source": [ 630 | "employees-(developers.union(Managers))" 631 | ] 632 | }, 633 | { 634 | "cell_type": "code", 635 | "execution_count": 45, 636 | "id": "40e4528d", 637 | "metadata": {}, 638 | "outputs": [ 639 | { 640 | "data": { 641 | "text/plain": [ 642 | "{'Rishabh'}" 643 | ] 644 | }, 645 | "execution_count": 45, 646 | "metadata": {}, 647 | "output_type": "execute_result" 648 | } 649 | ], 650 | "source": [ 651 | "gym_users&Managers" 652 | ] 653 | }, 654 | { 655 | "cell_type": "code", 656 | "execution_count": null, 657 | "id": "b739010f", 658 | "metadata": {}, 659 | "outputs": [], 660 | "source": [] 661 | } 662 | ], 663 | "metadata": { 664 | "kernelspec": { 665 | "display_name": "Python 3 (ipykernel)", 666 | "language": "python", 667 | "name": "python3" 668 | }, 669 | "language_info": { 670 | "codemirror_mode": { 671 | "name": "ipython", 672 | "version": 3 673 | }, 674 | "file_extension": ".py", 675 | "mimetype": "text/x-python", 676 | "name": "python", 677 | "nbconvert_exporter": "python", 678 | "pygments_lexer": "ipython3", 679 | "version": "3.8.10" 680 | } 681 | }, 682 | "nbformat": 4, 683 | "nbformat_minor": 5 684 | } 685 | -------------------------------------------------------------------------------- /sys_example.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | if len(sys.argv) != 3: 4 | print("USAGE: {} {} {}".format(sys.argv[0],"cust name" ,"acct num")) 5 | sys.exit(0) 6 | 7 | cust_name = sys.argv[1] 8 | acct_num = sys.argv[2] 9 | 10 | print("Program Name:",sys.argv[0]) 11 | print("Customer Name:",cust_name) 12 | print("Account Number:",acct_num) 13 | 14 | --------------------------------------------------------------------------------