├── .github └── ISSUE_TEMPLATE │ ├── custom.md │ └── feature_request.md ├── Decorators & Namespaces └── Decorators & Namespaces.ipynb ├── README.md ├── data ├── demo.json ├── person.pkl ├── sample.txt └── sample1.txt ├── docs ├── Readme.md └── visualize.md ├── notebooks ├── Conditionals and booleans.ipynb ├── Dictionaries.ipynb ├── Exception handling .ipynb ├── File Handling + Serialization & Deserialization-1.ipynb ├── File Handling + Serialization & Deserialization-2.ipynb ├── Function.ipynb ├── Lambda function.ipynb ├── Loops and iterators.ipynb ├── Matplotlib.ipynb ├── Numpy_Notes.ipynb ├── Pandas_Notes.ipynb ├── Python basics.ipynb ├── Seaborn 1.ipynb ├── Seaborn 2.ipynb ├── Seaborn 3.ipynb ├── Seaborn 4.ipynb ├── Untitled.ipynb └── pc_list.ipynb ├── resources ├── 52 Python Question Answers.pdf ├── Automate the Boring Stuff with Python.pdf ├── ListsOfInbuiltMethods.pdf ├── Python Notes.pdf ├── python cheat sheet.pdf └── python-crash-course.pdf └── scripts ├── 01.TwoSum.py ├── BinarySearch.py ├── LinearSearch.py ├── MergeSort.py ├── argparse_1.py ├── check.py ├── multithreading.py ├── pdf2doc.py └── toh.py /.github/ISSUE_TEMPLATE/custom.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Custom issue template 3 | about: Describe this issue template's purpose here. 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | # Prerequisites 11 | 12 | Please answer the following questions for yourself before submitting an issue. **YOU MAY DELETE THE PREREQUISITES SECTION.** 13 | 14 | - [ ] I am running the latest version 15 | - [ ] I checked the documentation and found no answer 16 | - [ ] I checked to make sure that this issue has not already been filed 17 | - [ ] I'm reporting the issue to the correct repository (for multi-repository projects) 18 | 19 | # Expected Behavior 20 | 21 | Please describe the behavior you are expecting 22 | 23 | # Current Behavior 24 | 25 | What is the current behavior? 26 | 27 | # Failure Information (for bugs) 28 | 29 | Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template. 30 | 31 | ## Steps to Reproduce 32 | 33 | Please provide detailed steps for reproducing the issue. 34 | 35 | 1. step 1 36 | 2. step 2 37 | 3. you get it... 38 | 39 | ## Context 40 | 41 | Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions. 42 | 43 | * Firmware Version: 44 | * Operating System: 45 | * SDK version: 46 | 47 | ## Failure Logs 48 | 49 | Please include any relevant log snippets or files here. 50 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /Decorators & Namespaces/Decorators & Namespaces.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "3bf8ae84", 6 | "metadata": {}, 7 | "source": [ 8 | "### Namespaces\n", 9 | "\n", 10 | "A namespace is a space that holds names(identifiers).Programmatically speaking, namespaces are dictionary of identifiers(keys) and their objects(values)\n", 11 | "\n", 12 | "There are 4 types of namespaces:\n", 13 | "- Builtin Namespace\n", 14 | "- Global Namespace\n", 15 | "- Enclosing Namespace\n", 16 | "- Local Namespace" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "683992da", 22 | "metadata": {}, 23 | "source": [ 24 | "### Scope and LEGB Rule\n", 25 | "\n", 26 | "A scope is a textual region of a Python program where a namespace is directly accessible.\n", 27 | "\n", 28 | "The interpreter searches for a name from the inside out, looking in the local, enclosing, global, and finally the built-in scope. If the interpreter doesn’t find the name in any of these locations, then Python raises a NameError exception." 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 4, 34 | "id": "74fc2794", 35 | "metadata": {}, 36 | "outputs": [ 37 | { 38 | "name": "stdout", 39 | "output_type": "stream", 40 | "text": [ 41 | "3\n", 42 | "2\n" 43 | ] 44 | } 45 | ], 46 | "source": [ 47 | "# local and global\n", 48 | "# global var\n", 49 | "a = 2\n", 50 | "\n", 51 | "def temp():\n", 52 | " # local var\n", 53 | " b = 3\n", 54 | " print(b)\n", 55 | "\n", 56 | "temp()\n", 57 | "print(a)" 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": 5, 63 | "id": "e232da38", 64 | "metadata": {}, 65 | "outputs": [ 66 | { 67 | "ename": "NameError", 68 | "evalue": "name 'b' is not defined", 69 | "output_type": "error", 70 | "traceback": [ 71 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 72 | "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", 73 | "Cell \u001b[1;32mIn[5], line 8\u001b[0m\n\u001b[0;32m 6\u001b[0m a \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m3\u001b[39m\n\u001b[0;32m 7\u001b[0m \u001b[38;5;28mprint\u001b[39m(b)\n\u001b[1;32m----> 8\u001b[0m \u001b[43mtemp\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 9\u001b[0m \u001b[38;5;28mprint\u001b[39m(a)\n", 74 | "Cell \u001b[1;32mIn[5], line 7\u001b[0m, in \u001b[0;36mtemp\u001b[1;34m()\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mtemp\u001b[39m():\n\u001b[0;32m 5\u001b[0m \u001b[38;5;66;03m# local var\u001b[39;00m\n\u001b[0;32m 6\u001b[0m a \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m3\u001b[39m\n\u001b[1;32m----> 7\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43mb\u001b[49m)\n", 75 | "\u001b[1;31mNameError\u001b[0m: name 'b' is not defined" 76 | ] 77 | } 78 | ], 79 | "source": [ 80 | "# local and global -> same name\n", 81 | "a = 2\n", 82 | "\n", 83 | "def temp():\n", 84 | " # local var\n", 85 | " a = 3\n", 86 | " print(b)\n", 87 | "temp()\n", 88 | "print(a)" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": 6, 94 | "id": "6e0ad875", 95 | "metadata": {}, 96 | "outputs": [ 97 | { 98 | "name": "stdout", 99 | "output_type": "stream", 100 | "text": [ 101 | "2\n", 102 | "2\n" 103 | ] 104 | } 105 | ], 106 | "source": [ 107 | "# local and global -> local does not have but global has\n", 108 | "a = 2\n", 109 | "\n", 110 | "def temp():\n", 111 | " # local var\n", 112 | " print(a)\n", 113 | "\n", 114 | "temp()\n", 115 | "print(a)\n" 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": 7, 121 | "id": "7ebd7446", 122 | "metadata": {}, 123 | "outputs": [ 124 | { 125 | "ename": "UnboundLocalError", 126 | "evalue": "local variable 'a' referenced before assignment", 127 | "output_type": "error", 128 | "traceback": [ 129 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 130 | "\u001b[1;31mUnboundLocalError\u001b[0m Traceback (most recent call last)", 131 | "Cell \u001b[1;32mIn[7], line 9\u001b[0m\n\u001b[0;32m 6\u001b[0m a \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1\u001b[39m\n\u001b[0;32m 7\u001b[0m \u001b[38;5;28mprint\u001b[39m(a)\n\u001b[1;32m----> 9\u001b[0m \u001b[43mtemp\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 10\u001b[0m \u001b[38;5;28mprint\u001b[39m(a)\n", 132 | "Cell \u001b[1;32mIn[7], line 6\u001b[0m, in \u001b[0;36mtemp\u001b[1;34m()\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mtemp\u001b[39m():\n\u001b[0;32m 5\u001b[0m \u001b[38;5;66;03m# local var\u001b[39;00m\n\u001b[1;32m----> 6\u001b[0m a \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1\u001b[39m\n\u001b[0;32m 7\u001b[0m \u001b[38;5;28mprint\u001b[39m(a)\n", 133 | "\u001b[1;31mUnboundLocalError\u001b[0m: local variable 'a' referenced before assignment" 134 | ] 135 | } 136 | ], 137 | "source": [ 138 | "# local and global -> editing global\n", 139 | "a = 2\n", 140 | "\n", 141 | "def temp():\n", 142 | " # local var\n", 143 | " a += 1\n", 144 | " print(a)\n", 145 | "\n", 146 | "temp()\n", 147 | "print(a)" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": 8, 153 | "id": "1ade4c83", 154 | "metadata": {}, 155 | "outputs": [ 156 | { 157 | "name": "stdout", 158 | "output_type": "stream", 159 | "text": [ 160 | "3\n", 161 | "3\n" 162 | ] 163 | } 164 | ], 165 | "source": [ 166 | "a = 2\n", 167 | "\n", 168 | "def temp():\n", 169 | " # local var\n", 170 | " global a\n", 171 | " a += 1\n", 172 | " print(a)\n", 173 | "\n", 174 | "temp()\n", 175 | "print(a)" 176 | ] 177 | }, 178 | { 179 | "cell_type": "code", 180 | "execution_count": 9, 181 | "id": "05bb5b70", 182 | "metadata": {}, 183 | "outputs": [ 184 | { 185 | "name": "stdout", 186 | "output_type": "stream", 187 | "text": [ 188 | "1\n", 189 | "1\n" 190 | ] 191 | } 192 | ], 193 | "source": [ 194 | "# local and global -> global created inside local\n", 195 | "def temp():\n", 196 | " # local var\n", 197 | " global a\n", 198 | " a = 1\n", 199 | " print(a)\n", 200 | "\n", 201 | "temp()\n", 202 | "print(a)" 203 | ] 204 | }, 205 | { 206 | "cell_type": "code", 207 | "execution_count": 10, 208 | "id": "000eb051", 209 | "metadata": {}, 210 | "outputs": [ 211 | { 212 | "name": "stdout", 213 | "output_type": "stream", 214 | "text": [ 215 | "5\n", 216 | "5\n" 217 | ] 218 | }, 219 | { 220 | "ename": "NameError", 221 | "evalue": "name 'z' is not defined", 222 | "output_type": "error", 223 | "traceback": [ 224 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 225 | "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", 226 | "Cell \u001b[1;32mIn[10], line 9\u001b[0m\n\u001b[0;32m 7\u001b[0m temp(\u001b[38;5;241m5\u001b[39m)\n\u001b[0;32m 8\u001b[0m \u001b[38;5;28mprint\u001b[39m(a)\n\u001b[1;32m----> 9\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43mz\u001b[49m)\n", 227 | "\u001b[1;31mNameError\u001b[0m: name 'z' is not defined" 228 | ] 229 | } 230 | ], 231 | "source": [ 232 | "# local and global -> function parameter is local\n", 233 | "def temp(z):\n", 234 | " # local var\n", 235 | " print(z)\n", 236 | "\n", 237 | "a = 5\n", 238 | "temp(5)\n", 239 | "print(a)\n", 240 | "print(z)" 241 | ] 242 | }, 243 | { 244 | "cell_type": "code", 245 | "execution_count": 11, 246 | "id": "3cf1c14c", 247 | "metadata": {}, 248 | "outputs": [ 249 | { 250 | "name": "stdout", 251 | "output_type": "stream", 252 | "text": [ 253 | "['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EncodingWarning', 'EnvironmentError', 'Exception', 'False', 'FileExistsError', 'FileNotFoundError', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'InterruptedError', 'IsADirectoryError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'ModuleNotFoundError', 'NameError', 'None', 'NotADirectoryError', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'PermissionError', 'ProcessLookupError', 'RecursionError', 'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning', 'StopAsyncIteration', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'TimeoutError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'WindowsError', 'ZeroDivisionError', '__IPYTHON__', '__build_class__', '__debug__', '__doc__', '__import__', '__loader__', '__name__', '__package__', '__spec__', 'abs', 'aiter', 'all', 'anext', 'any', 'ascii', 'bin', 'bool', 'breakpoint', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'display', 'divmod', 'enumerate', 'eval', 'exec', 'execfile', 'filter', 'float', 'format', 'frozenset', 'get_ipython', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'range', 'repr', 'reversed', 'round', 'runfile', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip']\n" 254 | ] 255 | } 256 | ], 257 | "source": [ 258 | "# built-in scope\n", 259 | "import builtins\n", 260 | "print(dir(builtins))" 261 | ] 262 | }, 263 | { 264 | "cell_type": "code", 265 | "execution_count": 12, 266 | "id": "c830ea9c", 267 | "metadata": {}, 268 | "outputs": [], 269 | "source": [ 270 | "# how to see all the built-ins" 271 | ] 272 | }, 273 | { 274 | "cell_type": "code", 275 | "execution_count": 13, 276 | "id": "e980feb9", 277 | "metadata": {}, 278 | "outputs": [ 279 | { 280 | "name": "stdout", 281 | "output_type": "stream", 282 | "text": [ 283 | "3\n" 284 | ] 285 | }, 286 | { 287 | "ename": "TypeError", 288 | "evalue": "max() takes 0 positional arguments but 1 was given", 289 | "output_type": "error", 290 | "traceback": [ 291 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 292 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 293 | "Cell \u001b[1;32mIn[13], line 7\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mmax\u001b[39m():\n\u001b[0;32m 5\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mhello\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m----> 7\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28;43mmax\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mL\u001b[49m\u001b[43m)\u001b[49m)\n", 294 | "\u001b[1;31mTypeError\u001b[0m: max() takes 0 positional arguments but 1 was given" 295 | ] 296 | } 297 | ], 298 | "source": [ 299 | "# renaming built-ins\n", 300 | "L = [1,2,3]\n", 301 | "print(max(L))\n", 302 | "def max():\n", 303 | " print('hello')\n", 304 | "\n", 305 | "print(max(L))" 306 | ] 307 | }, 308 | { 309 | "cell_type": "code", 310 | "execution_count": 14, 311 | "id": "74f94a72", 312 | "metadata": {}, 313 | "outputs": [ 314 | { 315 | "name": "stdout", 316 | "output_type": "stream", 317 | "text": [ 318 | "5\n", 319 | "outer function\n", 320 | "main program\n" 321 | ] 322 | } 323 | ], 324 | "source": [ 325 | "# Enclosing scope\n", 326 | "def outer():\n", 327 | " def inner():\n", 328 | " print(a)\n", 329 | " inner()\n", 330 | " print('outer function')\n", 331 | "\n", 332 | "\n", 333 | "outer()\n", 334 | "print('main program')" 335 | ] 336 | }, 337 | { 338 | "cell_type": "code", 339 | "execution_count": 15, 340 | "id": "60bd2b84", 341 | "metadata": {}, 342 | "outputs": [ 343 | { 344 | "name": "stdout", 345 | "output_type": "stream", 346 | "text": [ 347 | "inner 2\n", 348 | "outer 2\n", 349 | "main program\n" 350 | ] 351 | } 352 | ], 353 | "source": [ 354 | "# nonlocal keyword\n", 355 | "def outer():\n", 356 | " a = 1\n", 357 | " def inner():\n", 358 | " nonlocal a\n", 359 | " a += 1\n", 360 | " print('inner',a)\n", 361 | " inner()\n", 362 | " print('outer',a)\n", 363 | "\n", 364 | "\n", 365 | "outer()\n", 366 | "print('main program')" 367 | ] 368 | }, 369 | { 370 | "cell_type": "markdown", 371 | "id": "bf269d28", 372 | "metadata": {}, 373 | "source": [ 374 | "### Decorators\n", 375 | "\n", 376 | "A decorator in python is a function that receives another function as input and adds some functionality(decoration) to and it and returns it.\n", 377 | "\n", 378 | "This can happen only because python functions are 1st class citizens.\n", 379 | "\n", 380 | "There are 2 types of decorators available in python\n", 381 | "- `Built in decorators` like `@staticmethod`, `@classmethod`, `@abstractmethod` and `@property` etc\n", 382 | "- `User defined decorators` that we programmers can create according to our needs" 383 | ] 384 | }, 385 | { 386 | "cell_type": "code", 387 | "execution_count": 16, 388 | "id": "8d397cea", 389 | "metadata": {}, 390 | "outputs": [ 391 | { 392 | "data": { 393 | "text/plain": [ 394 | "4" 395 | ] 396 | }, 397 | "execution_count": 16, 398 | "metadata": {}, 399 | "output_type": "execute_result" 400 | } 401 | ], 402 | "source": [ 403 | "# Python are 1st class function\n", 404 | "\n", 405 | "def modify(func,num):\n", 406 | " return func(num)\n", 407 | "\n", 408 | "def square(num):\n", 409 | " return num**2\n", 410 | "\n", 411 | "modify(square,2)" 412 | ] 413 | }, 414 | { 415 | "cell_type": "code", 416 | "execution_count": 27, 417 | "id": "2d92a88c", 418 | "metadata": {}, 419 | "outputs": [ 420 | { 421 | "name": "stdout", 422 | "output_type": "stream", 423 | "text": [ 424 | "***********************\n", 425 | "hello\n", 426 | "***********************\n", 427 | "***********************\n", 428 | "hello Utkarsh\n", 429 | "***********************\n" 430 | ] 431 | } 432 | ], 433 | "source": [ 434 | "# simple example\n", 435 | "\n", 436 | "def my_decorator(func):\n", 437 | " def wrapper():\n", 438 | " print('***********************')\n", 439 | " func()\n", 440 | " print('***********************')\n", 441 | " return wrapper\n", 442 | "\n", 443 | "def hello():\n", 444 | " print('hello')\n", 445 | "\n", 446 | "def display():\n", 447 | " print('hello Utkarsh')\n", 448 | "\n", 449 | "a = my_decorator(hello)\n", 450 | "a()\n", 451 | "\n", 452 | "b = my_decorator(display)\n", 453 | "b()" 454 | ] 455 | }, 456 | { 457 | "cell_type": "code", 458 | "execution_count": 18, 459 | "id": "bd41c1f8", 460 | "metadata": {}, 461 | "outputs": [], 462 | "source": [ 463 | "# more functions" 464 | ] 465 | }, 466 | { 467 | "cell_type": "code", 468 | "execution_count": 19, 469 | "id": "06cf543a", 470 | "metadata": {}, 471 | "outputs": [], 472 | "source": [ 473 | "# how this works -> closure?" 474 | ] 475 | }, 476 | { 477 | "cell_type": "code", 478 | "execution_count": 20, 479 | "id": "490c4969", 480 | "metadata": {}, 481 | "outputs": [], 482 | "source": [ 483 | "# python tutor" 484 | ] 485 | }, 486 | { 487 | "cell_type": "code", 488 | "execution_count": 21, 489 | "id": "7913a3a3", 490 | "metadata": {}, 491 | "outputs": [ 492 | { 493 | "name": "stdout", 494 | "output_type": "stream", 495 | "text": [ 496 | "***********************\n", 497 | "hello\n", 498 | "***********************\n" 499 | ] 500 | } 501 | ], 502 | "source": [ 503 | "# Better syntax?\n", 504 | "# simple example\n", 505 | "\n", 506 | "def my_decorator(func):\n", 507 | " def wrapper():\n", 508 | " print('***********************')\n", 509 | " func()\n", 510 | " print('***********************')\n", 511 | " return wrapper\n", 512 | "\n", 513 | "@my_decorator\n", 514 | "def hello():\n", 515 | " print('hello')\n", 516 | "\n", 517 | "hello()" 518 | ] 519 | }, 520 | { 521 | "cell_type": "code", 522 | "execution_count": 28, 523 | "id": "bf9ae6f5", 524 | "metadata": {}, 525 | "outputs": [ 526 | { 527 | "name": "stdout", 528 | "output_type": "stream", 529 | "text": [ 530 | "hello world\n", 531 | "time taken by hello 2.0009565353393555 secs\n", 532 | "4\n", 533 | "time taken by square 1.0055112838745117 secs\n", 534 | "8\n", 535 | "time taken by power 0.0 secs\n" 536 | ] 537 | } 538 | ], 539 | "source": [ 540 | "# anything meaningful?\n", 541 | "import time\n", 542 | "\n", 543 | "def timer(func):\n", 544 | " def wrapper(*args):\n", 545 | " start = time.time()\n", 546 | " func(*args)\n", 547 | " print('time taken by',func.__name__,time.time()-start,'secs')\n", 548 | " return wrapper\n", 549 | "\n", 550 | "@timer\n", 551 | "def hello():\n", 552 | " print('hello world')\n", 553 | " time.sleep(2)\n", 554 | "\n", 555 | "@timer\n", 556 | "def square(num):\n", 557 | " time.sleep(1)\n", 558 | " print(num**2)\n", 559 | "\n", 560 | "@timer\n", 561 | "def power(a,b):\n", 562 | " print(a**b)\n", 563 | "\n", 564 | "hello()\n", 565 | "square(2)\n", 566 | "power(2,3)\n" 567 | ] 568 | }, 569 | { 570 | "cell_type": "code", 571 | "execution_count": 23, 572 | "id": "ec5242c1", 573 | "metadata": {}, 574 | "outputs": [], 575 | "source": [ 576 | "# A big problem" 577 | ] 578 | }, 579 | { 580 | "cell_type": "code", 581 | "execution_count": 24, 582 | "id": "ac768470", 583 | "metadata": {}, 584 | "outputs": [], 585 | "source": [ 586 | "# One last example -> decorators with arguments" 587 | ] 588 | }, 589 | { 590 | "cell_type": "code", 591 | "execution_count": 25, 592 | "id": "88f4e43f", 593 | "metadata": {}, 594 | "outputs": [ 595 | { 596 | "ename": "NameError", 597 | "evalue": "name 'checkdt' is not defined", 598 | "output_type": "error", 599 | "traceback": [ 600 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 601 | "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", 602 | "Cell \u001b[1;32mIn[25], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;129m@checkdt\u001b[39m(\u001b[38;5;28mint\u001b[39m)\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21msquare\u001b[39m(num):\n\u001b[0;32m 3\u001b[0m \u001b[38;5;28mprint\u001b[39m(num\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m2\u001b[39m)\n", 603 | "\u001b[1;31mNameError\u001b[0m: name 'checkdt' is not defined" 604 | ] 605 | } 606 | ], 607 | "source": [ 608 | "@checkdt(int)\n", 609 | "def square(num):\n", 610 | " print(num**2)" 611 | ] 612 | }, 613 | { 614 | "cell_type": "code", 615 | "execution_count": 29, 616 | "id": "8aeafe82", 617 | "metadata": {}, 618 | "outputs": [ 619 | { 620 | "name": "stdout", 621 | "output_type": "stream", 622 | "text": [ 623 | "4\n" 624 | ] 625 | } 626 | ], 627 | "source": [ 628 | "def sanity_check(data_type):\n", 629 | " def outer_wrapper(func):\n", 630 | " def inner_wrapper(*args):\n", 631 | " if type(*args) == data_type:\n", 632 | " func(*args)\n", 633 | " else:\n", 634 | " raise TypeError('This datatype may not work')\n", 635 | " return inner_wrapper\n", 636 | " return outer_wrapper\n", 637 | "\n", 638 | "@sanity_check(int)\n", 639 | "def square(num):\n", 640 | " print(num**2)\n", 641 | "\n", 642 | "@sanity_check(str)\n", 643 | "def greet(name):\n", 644 | " print('hello',name)\n", 645 | "\n", 646 | "square(2)" 647 | ] 648 | }, 649 | { 650 | "cell_type": "code", 651 | "execution_count": null, 652 | "id": "9ea0e815", 653 | "metadata": {}, 654 | "outputs": [], 655 | "source": [] 656 | } 657 | ], 658 | "metadata": { 659 | "kernelspec": { 660 | "display_name": "Python 3 (ipykernel)", 661 | "language": "python", 662 | "name": "python3" 663 | }, 664 | "language_info": { 665 | "codemirror_mode": { 666 | "name": "ipython", 667 | "version": 3 668 | }, 669 | "file_extension": ".py", 670 | "mimetype": "text/x-python", 671 | "name": "python", 672 | "nbconvert_exporter": "python", 673 | "pygments_lexer": "ipython3", 674 | "version": "3.10.9" 675 | } 676 | }, 677 | "nbformat": 4, 678 | "nbformat_minor": 5 679 | } 680 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python-for-beginners 2 | 3 | Welcome! This repository is designed for anyone starting with Python, offering hands-on practice with core concepts, data types, and essential libraries like Matplotlib, Pandas, and NumPy. It also includes useful real-world topics such as file handling, serialization, exception handling, and more. 4 | 5 | #### Try this quiz to check your Level in python! 6 | 7 | [Quiz](https://pppwebapp.web.app/) 8 | 9 | --- 10 | 11 | ## 📁 Repository Structure 12 | 13 | To make it easy for you to find what you need, here’s how the files and folders are organized: 14 | 15 | ``` 16 | Python-for-beginners/ 17 | │ 18 | ├── notebooks/ # Jupyter notebooks for interactive learning (Numpy, Pandas, Seaborn, etc.) 19 | ├── scripts/ # Standalone Python scripts for algorithms, demos, and exercises 20 | ├── resources/ # PDF books, cheat sheets, and other learning materials 21 | ├── docs/ # Documentation and extra guides 22 | ├── data/ # Sample data files for practice 23 | ├── .github/ # GitHub configuration files 24 | ├── README.md # You are here! Main guide for the repo 25 | └── requirements.txt# (Add your dependencies here if needed) 26 | ``` 27 | 28 | ### What you’ll find in each folder: 29 | - **notebooks/**: Interactive, step-by-step explanations and code for each topic. Great for experimentation! 30 | - **scripts/**: Ready-to-run Python files for algorithms (searching, sorting, etc.), examples, and small projects. 31 | - **resources/**: Handy PDFs, notes, and cheat sheets for quick reference. 32 | - **docs/**: Extra documentation or guides (e.g., how to use a package). 33 | - **data/**: Small datasets or files for practicing file handling and data analysis. 34 | 35 | --- 36 | 37 | ## Installation 38 | 39 | Additionally, the project utilizes several external libraries, including Matplotlib, Pandas, and NumPy. These libraries can be installed using pip, the Python package manager. Run the following command to install the dependencies: 40 | 41 | ```shell 42 | pip install matplotlib pandas numpy 43 | ``` 44 | 45 | 46 | ## Data Types 47 | 48 | The project covers various data types in Python, including: 49 | 50 | - Numeric types: int, float 51 | - Boolean type: bool 52 | - Sequence types: str, list, tuple 53 | - Mapping type: dict 54 | - Set types: set 55 | 56 | ## Libraries 57 | 58 | 1. Matplotlib: A popular data visualization library that provides a wide range of plotting options, enabling the creation of various charts, graphs, and visualizations. 59 | 60 | 2. Pandas: A powerful library for data manipulation and analysis. Pandas provides data structures and functions to efficiently handle structured data, perform data cleaning, filtering, aggregation, and more. 61 | 62 | 3. NumPy: A fundamental library for numerical computing in Python. NumPy provides support for handling large, multi-dimensional arrays and a collection of mathematical functions for efficient numerical operations. 63 | 64 | 4. Seaborn: A data visualization library that provides a wide range of plotting options and also require less line of code than matplotlib with more number of plotting options like heatmap etc. 65 | 66 | ## For Contribution 67 | 68 | 69 | _If you're not comfortable with command line, [here are tutorials using GUI tools.](#tutorials-using-other-tools)_ 70 | 71 | 72 | #### If you don't have git on your machine, [install it](https://docs.github.com/en/get-started/quickstart/set-up-git). 73 | 74 | ## Fork this repository 75 | 76 | Fork this repository by clicking on the fork button on the top of this page. 77 | This will create a copy of this repository in your account. 78 | 79 | ## Clone the repository 80 | 81 | Now clone the forked repository to your machine. Go to your GitHub account, open the forked repository, click on the code button and then click the _copy to clipboard_ icon. 82 | 83 | Open a terminal and run the following git command: 84 | 85 | ``` 86 | git clone "url you just copied" 87 | ``` 88 | 89 | where "url you just copied" (without the quotation marks) is the url to this repository (your fork of this project). See the previous steps to obtain the url. 90 | 91 | For example: 92 | 93 | ``` 94 | git clone git@github.com:this-is-you/Python-for-begineers.git 95 | ``` 96 | 97 | where `this-is-you` is your GitHub username. Here you're copying the contents of the first-contributions repository on GitHub to your computer. 98 | 99 | ## Create a branch 100 | 101 | Change to the repository directory on your computer (if you are not already there): 102 | 103 | ``` 104 | cd Python-for-begineers 105 | ``` 106 | 107 | Now create a branch using the `git switch` command: 108 | 109 | ``` 110 | git switch -c your-new-branch-name 111 | ``` 112 | 113 | For example: 114 | 115 | ``` 116 | git switch -c add-alonzo-church 117 | ``` 118 | 119 | ## Make necessary changes and commit those changes 120 | 121 | If you go to the project directory and execute the command `git status`, you'll see there are changes. 122 | 123 | Add those changes to the branch you just created using the `git add` command: 124 | 125 | ``` 126 | git add 127 | ``` 128 | 129 | Now commit those changes using the `git commit` command: 130 | 131 | ``` 132 | git commit -m "Add appropriate message" 133 | ``` 134 | 135 | ## Push changes to GitHub 136 | 137 | Push your changes using the command `git push`: 138 | 139 | ``` 140 | git push -u origin your-branch-name 141 | ``` 142 | 143 | replacing `your-branch-name` with the name of the branch you created earlier. 144 | 145 | ## Submit your changes for review 146 | 147 | If you go to your repository on GitHub, you'll see a `Compare & pull request` button. Click on that button. 148 | 149 | Now submit the pull request. 150 | 151 | **Happy coding!** 152 | -------------------------------------------------------------------------------- /data/demo.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Utkarsh Upadhyay", 3 | "age": 20, 4 | "gender": "male" 5 | } -------------------------------------------------------------------------------- /data/person.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utk2103/Python-for-beginners/e39e272a76d0efb70f860f0a23a9a6ae58a09c3b/data/person.pkl -------------------------------------------------------------------------------- /data/sample.txt: -------------------------------------------------------------------------------- 1 | hello world -------------------------------------------------------------------------------- /data/sample1.txt: -------------------------------------------------------------------------------- 1 | Xallo -------------------------------------------------------------------------------- /docs/Readme.md: -------------------------------------------------------------------------------- 1 | # pdf to docx 2 | 3 | ### Installation 4 | ```shell 5 | $ pip install pdf2docx 6 | ``` 7 | ```shell 8 | $ pip install --upgrade pdf2docx 9 | ``` 10 | 11 | Uninstall it 12 | ```shell 13 | $ pip uninstall pdf2docx 14 | ``` 15 | -------------------------------------------------------------------------------- /docs/visualize.md: -------------------------------------------------------------------------------- 1 | `Visualisation of tower of hanoi` 2 | 3 | ![1_vVL-OD3M5iCR2HcuXwuD9g](https://github.com/utk2103/Learning_python/assets/118432516/d6137376-3be9-4b87-a644-486e39e02aed) 4 | -------------------------------------------------------------------------------- /notebooks/Conditionals and booleans.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "a8e1dd5a", 6 | "metadata": {}, 7 | "source": [ 8 | "# Conditionals and booleans\n", 9 | "In this lesson we're learning about conditionals if else elif statement\n" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": 4, 15 | "id": "f98a9526", 16 | "metadata": {}, 17 | "outputs": [ 18 | { 19 | "name": "stdout", 20 | "output_type": "stream", 21 | "text": [ 22 | "Condition is true\n" 23 | ] 24 | } 25 | ], 26 | "source": [ 27 | "if True:\n", 28 | " print('Condition is true')" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 5, 34 | "id": "eedd14ba", 35 | "metadata": {}, 36 | "outputs": [], 37 | "source": [ 38 | "if False:\n", 39 | " print('Condition is false')" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": 6, 45 | "id": "e96daa41", 46 | "metadata": {}, 47 | "outputs": [ 48 | { 49 | "name": "stdout", 50 | "output_type": "stream", 51 | "text": [ 52 | "Language is python\n" 53 | ] 54 | } 55 | ], 56 | "source": [ 57 | "language = 'Python'\n", 58 | "if language == 'Python':\n", 59 | " print(\"Language is python\")\n", 60 | "else:\n", 61 | " print(\"No matching\")" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": 7, 67 | "id": "46416248", 68 | "metadata": {}, 69 | "outputs": [ 70 | { 71 | "name": "stdout", 72 | "output_type": "stream", 73 | "text": [ 74 | "No matching\n" 75 | ] 76 | } 77 | ], 78 | "source": [ 79 | "language = 'Java'\n", 80 | "if language == 'Python':\n", 81 | " print(\"Language is python\")\n", 82 | "else:\n", 83 | " print(\"No matching\")" 84 | ] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": 12, 89 | "id": "2f15b8da", 90 | "metadata": {}, 91 | "outputs": [ 92 | { 93 | "name": "stdout", 94 | "output_type": "stream", 95 | "text": [ 96 | "Language is Java\n" 97 | ] 98 | } 99 | ], 100 | "source": [ 101 | "language = 'Java'\n", 102 | "if language == 'Python':\n", 103 | " print(\"Language is python\")\n", 104 | "elif language == 'Javascript':\n", 105 | " print(\"Language is Javascript\")\n", 106 | "elif language == 'Java':\n", 107 | " print(\"Language is Java\") \n", 108 | "else:\n", 109 | " print(\"No matching\")" 110 | ] 111 | }, 112 | { 113 | "cell_type": "code", 114 | "execution_count": 22, 115 | "id": "84bc8422", 116 | "metadata": {}, 117 | "outputs": [ 118 | { 119 | "name": "stdout", 120 | "output_type": "stream", 121 | "text": [ 122 | "Good info\n" 123 | ] 124 | } 125 | ], 126 | "source": [ 127 | "Name = 'Utkarsh'\n", 128 | "Surname ='Upadhyay'\n", 129 | "logged_in ='True'\n", 130 | "if Name == 'Utkarsh' or Surname or logged_in:\n", 131 | " print('Good info')\n", 132 | "else:\n", 133 | " print('Badd info')" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": 1, 139 | "id": "4c59c962", 140 | "metadata": {}, 141 | "outputs": [ 142 | { 143 | "name": "stdout", 144 | "output_type": "stream", 145 | "text": [ 146 | "Admin page\n" 147 | ] 148 | } 149 | ], 150 | "source": [ 151 | "user = 'Admin'\n", 152 | "logged_in = True\n", 153 | "if user == 'Admin' and logged_in:\n", 154 | " print('Admin page')\n", 155 | "else:\n", 156 | " print('Bad creds')" 157 | ] 158 | }, 159 | { 160 | "cell_type": "code", 161 | "execution_count": 2, 162 | "id": "fed48ad4", 163 | "metadata": {}, 164 | "outputs": [ 165 | { 166 | "name": "stdout", 167 | "output_type": "stream", 168 | "text": [ 169 | "Bad creds\n" 170 | ] 171 | } 172 | ], 173 | "source": [ 174 | "user = 'Admin'\n", 175 | "logged_in = False\n", 176 | "if user == 'Admin' and logged_in:\n", 177 | " print('Admin page')\n", 178 | "else:\n", 179 | " print('Bad creds')" 180 | ] 181 | }, 182 | { 183 | "cell_type": "code", 184 | "execution_count": 3, 185 | "id": "1f04736b", 186 | "metadata": {}, 187 | "outputs": [ 188 | { 189 | "name": "stdout", 190 | "output_type": "stream", 191 | "text": [ 192 | "Admin page\n" 193 | ] 194 | } 195 | ], 196 | "source": [ 197 | "user = 'Admin'\n", 198 | "logged_in = False\n", 199 | "if user == 'Admin' or logged_in:\n", 200 | " print('Admin page')\n", 201 | "else:\n", 202 | " print('Bad creds')" 203 | ] 204 | }, 205 | { 206 | "cell_type": "code", 207 | "execution_count": 4, 208 | "id": "e35fdb14", 209 | "metadata": {}, 210 | "outputs": [ 211 | { 212 | "name": "stdout", 213 | "output_type": "stream", 214 | "text": [ 215 | "Please Log In\n" 216 | ] 217 | } 218 | ], 219 | "source": [ 220 | "user = 'Admin'\n", 221 | "logged_in = False\n", 222 | "if not logged_in:\n", 223 | " print('Please Log In')\n", 224 | "else:\n", 225 | " print('Welcome')" 226 | ] 227 | }, 228 | { 229 | "cell_type": "markdown", 230 | "id": "8b183203", 231 | "metadata": {}, 232 | "source": [ 233 | "Difference between is and ==\n", 234 | "is-- checks whether the object are same in memory or not like memory having same address which we can see in IN 8,9\n", 235 | "and == -- checks whether the object in the memory are same or not\n" 236 | ] 237 | }, 238 | { 239 | "cell_type": "code", 240 | "execution_count": 6, 241 | "id": "813f897b", 242 | "metadata": {}, 243 | "outputs": [ 244 | { 245 | "name": "stdout", 246 | "output_type": "stream", 247 | "text": [ 248 | "True\n" 249 | ] 250 | } 251 | ], 252 | "source": [ 253 | "a=[1,2,3]\n", 254 | "b=[1,2,3]\n", 255 | "print(a==b)" 256 | ] 257 | }, 258 | { 259 | "cell_type": "code", 260 | "execution_count": 7, 261 | "id": "5aef3459", 262 | "metadata": {}, 263 | "outputs": [ 264 | { 265 | "name": "stdout", 266 | "output_type": "stream", 267 | "text": [ 268 | "False\n" 269 | ] 270 | } 271 | ], 272 | "source": [ 273 | "a=[1,2,3]\n", 274 | "b=[1,2,3]\n", 275 | "print(a is b)" 276 | ] 277 | }, 278 | { 279 | "cell_type": "code", 280 | "execution_count": 8, 281 | "id": "bcce003c", 282 | "metadata": {}, 283 | "outputs": [ 284 | { 285 | "name": "stdout", 286 | "output_type": "stream", 287 | "text": [ 288 | "1509811759488\n", 289 | "1509811760128\n", 290 | "False\n" 291 | ] 292 | } 293 | ], 294 | "source": [ 295 | "a=[1,2,3]\n", 296 | "b=[1,2,3]\n", 297 | "print(id(a))\n", 298 | "print(id(b))\n", 299 | "print(a is b)" 300 | ] 301 | }, 302 | { 303 | "cell_type": "code", 304 | "execution_count": 9, 305 | "id": "de019d20", 306 | "metadata": {}, 307 | "outputs": [ 308 | { 309 | "name": "stdout", 310 | "output_type": "stream", 311 | "text": [ 312 | "1509811753856\n", 313 | "1509811753856\n", 314 | "True\n" 315 | ] 316 | } 317 | ], 318 | "source": [ 319 | "a = [1,2,3]\n", 320 | "b = a\n", 321 | "print(id(a))\n", 322 | "print(id(b))\n", 323 | "print(a==b)" 324 | ] 325 | }, 326 | { 327 | "cell_type": "markdown", 328 | "id": "5f3d4153", 329 | "metadata": {}, 330 | "source": [ 331 | "# False values:\n", 332 | " *False \n", 333 | " *None \n", 334 | " *Zero of any numeric type \n", 335 | " *Any empty sequence. For example, '',(),[].\n", 336 | " *Any empty mapping. For example, {}.\n", 337 | " " 338 | ] 339 | }, 340 | { 341 | "cell_type": "code", 342 | "execution_count": 10, 343 | "id": "e50449f9", 344 | "metadata": {}, 345 | "outputs": [ 346 | { 347 | "name": "stdout", 348 | "output_type": "stream", 349 | "text": [ 350 | "Evaluated to False\n" 351 | ] 352 | } 353 | ], 354 | "source": [ 355 | "condition = False\n", 356 | "\n", 357 | "if condition:\n", 358 | " print('Evaluated to True')\n", 359 | "else:\n", 360 | " print('Evaluated to False')" 361 | ] 362 | }, 363 | { 364 | "cell_type": "code", 365 | "execution_count": 11, 366 | "id": "7a265768", 367 | "metadata": {}, 368 | "outputs": [ 369 | { 370 | "name": "stdout", 371 | "output_type": "stream", 372 | "text": [ 373 | "Evaluated to False\n" 374 | ] 375 | } 376 | ], 377 | "source": [ 378 | "condition = None\n", 379 | "\n", 380 | "if condition:\n", 381 | " print('Evaluated to True')\n", 382 | "else:\n", 383 | " print('Evaluated to False')" 384 | ] 385 | }, 386 | { 387 | "cell_type": "code", 388 | "execution_count": 12, 389 | "id": "e0a96d04", 390 | "metadata": {}, 391 | "outputs": [ 392 | { 393 | "name": "stdout", 394 | "output_type": "stream", 395 | "text": [ 396 | "Evaluated to False\n" 397 | ] 398 | } 399 | ], 400 | "source": [ 401 | "condition = 0\n", 402 | "\n", 403 | "if condition:\n", 404 | " print('Evaluated to True')\n", 405 | "else:\n", 406 | " print('Evaluated to False')" 407 | ] 408 | }, 409 | { 410 | "cell_type": "code", 411 | "execution_count": 13, 412 | "id": "772d5f77", 413 | "metadata": {}, 414 | "outputs": [ 415 | { 416 | "name": "stdout", 417 | "output_type": "stream", 418 | "text": [ 419 | "Evaluated to True\n" 420 | ] 421 | } 422 | ], 423 | "source": [ 424 | "condition = 10\n", 425 | "\n", 426 | "if condition:\n", 427 | " print('Evaluated to True')\n", 428 | "else:\n", 429 | " print('Evaluated to False')" 430 | ] 431 | }, 432 | { 433 | "cell_type": "code", 434 | "execution_count": 14, 435 | "id": "6cdb232c", 436 | "metadata": {}, 437 | "outputs": [ 438 | { 439 | "name": "stdout", 440 | "output_type": "stream", 441 | "text": [ 442 | "Evaluated to False\n" 443 | ] 444 | } 445 | ], 446 | "source": [ 447 | "condition = []\n", 448 | "\n", 449 | "if condition:\n", 450 | " print('Evaluated to True')\n", 451 | "else:\n", 452 | " print('Evaluated to False')" 453 | ] 454 | }, 455 | { 456 | "cell_type": "code", 457 | "execution_count": null, 458 | "id": "0379af96", 459 | "metadata": {}, 460 | "outputs": [], 461 | "source": [] 462 | } 463 | ], 464 | "metadata": { 465 | "kernelspec": { 466 | "display_name": "Python 3 (ipykernel)", 467 | "language": "python", 468 | "name": "python3" 469 | }, 470 | "language_info": { 471 | "codemirror_mode": { 472 | "name": "ipython", 473 | "version": 3 474 | }, 475 | "file_extension": ".py", 476 | "mimetype": "text/x-python", 477 | "name": "python", 478 | "nbconvert_exporter": "python", 479 | "pygments_lexer": "ipython3", 480 | "version": "3.10.9" 481 | } 482 | }, 483 | "nbformat": 4, 484 | "nbformat_minor": 5 485 | } 486 | -------------------------------------------------------------------------------- /notebooks/Dictionaries.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "ed3bf423", 6 | "metadata": {}, 7 | "source": [ 8 | "# Dictionaries\n", 9 | " In other languages it is also called hash maps or associative arrays." 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": 1, 15 | "id": "e7560322", 16 | "metadata": {}, 17 | "outputs": [ 18 | { 19 | "name": "stdout", 20 | "output_type": "stream", 21 | "text": [ 22 | "['compsci', 'maths']\n" 23 | ] 24 | } 25 | ], 26 | "source": [ 27 | "student ={'name': 'Utkarsh', 'age':20, 'courses':['compsci','maths']}\n", 28 | "print(student['courses'])" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 2, 34 | "id": "00e07c62", 35 | "metadata": {}, 36 | "outputs": [ 37 | { 38 | "name": "stdout", 39 | "output_type": "stream", 40 | "text": [ 41 | "Utkarsh\n" 42 | ] 43 | } 44 | ], 45 | "source": [ 46 | "student ={'name': 'Utkarsh', 'age':20, 'courses':['compsci','maths']}\n", 47 | "print(student.get('name')) ##Same as before " 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": 3, 53 | "id": "de3b5e62", 54 | "metadata": {}, 55 | "outputs": [ 56 | { 57 | "name": "stdout", 58 | "output_type": "stream", 59 | "text": [ 60 | "Not found\n" 61 | ] 62 | } 63 | ], 64 | "source": [ 65 | "student ={'name': 'Utkarsh', 'age':20, 'courses':['compsci','maths']}\n", 66 | "print(student.get('phone','Not found'))" 67 | ] 68 | }, 69 | { 70 | "cell_type": "code", 71 | "execution_count": 4, 72 | "id": "90fa407d", 73 | "metadata": {}, 74 | "outputs": [ 75 | { 76 | "name": "stdout", 77 | "output_type": "stream", 78 | "text": [ 79 | "20\n" 80 | ] 81 | } 82 | ], 83 | "source": [ 84 | "student ={'name': 'Utkarsh', 'age':20, 'courses':['compsci','maths']}\n", 85 | "print(student.get('age','Found'))" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": 5, 91 | "id": "3dedd773", 92 | "metadata": {}, 93 | "outputs": [], 94 | "source": [ 95 | "##Adding a element in a dictionaries\n" 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": 6, 101 | "id": "9f715644", 102 | "metadata": {}, 103 | "outputs": [ 104 | { 105 | "name": "stdout", 106 | "output_type": "stream", 107 | "text": [ 108 | "{'name': 'Jane', 'age': 23, 'courses': ['Physics']}\n" 109 | ] 110 | } 111 | ], 112 | "source": [ 113 | "##Updating a element in a dictionary\n", 114 | "student ={'name': 'Utkarsh', 'age':20, 'courses':['compsci','maths']}\n", 115 | "student ={'name': 'Jane' , 'age':23 , 'courses':['Physics']}\n", 116 | "print(student)" 117 | ] 118 | }, 119 | { 120 | "cell_type": "code", 121 | "execution_count": 8, 122 | "id": "9e8ec83a", 123 | "metadata": {}, 124 | "outputs": [ 125 | { 126 | "name": "stdout", 127 | "output_type": "stream", 128 | "text": [ 129 | "{'name': 'Jane', 'age': 23, 'courses': ['Physics']}\n" 130 | ] 131 | } 132 | ], 133 | "source": [ 134 | "##ANother updating method\n", 135 | "student ={'name': 'Utkarsh', 'age':20, 'courses':['compsci','maths']}\n", 136 | "student.update({'name': 'Jane' , 'age':23 , 'courses':['Physics']})\n", 137 | "print(student)" 138 | ] 139 | }, 140 | { 141 | "cell_type": "code", 142 | "execution_count": 1, 143 | "id": "2df6760e", 144 | "metadata": {}, 145 | "outputs": [ 146 | { 147 | "name": "stdout", 148 | "output_type": "stream", 149 | "text": [ 150 | "{'name': 'Utkarsh', 'courses': ['compsci', 'maths']}\n" 151 | ] 152 | } 153 | ], 154 | "source": [ 155 | "##Delete method\n", 156 | "student ={'name': 'Utkarsh', 'age':20, 'courses':['compsci','maths']}\n", 157 | "del student['age']\n", 158 | "print(student)" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": 3, 164 | "id": "ffcfbed2", 165 | "metadata": {}, 166 | "outputs": [ 167 | { 168 | "name": "stdout", 169 | "output_type": "stream", 170 | "text": [ 171 | "{'name': 'Utkarsh', 'courses': ['compsci', 'maths']}\n" 172 | ] 173 | } 174 | ], 175 | "source": [ 176 | "## Another Delete method\n", 177 | "student ={'name': 'Utkarsh', 'age':20, 'courses':['compsci','maths']}\n", 178 | "age = student.pop('age')\n", 179 | "print(student)" 180 | ] 181 | }, 182 | { 183 | "cell_type": "code", 184 | "execution_count": 4, 185 | "id": "786a1d35", 186 | "metadata": {}, 187 | "outputs": [ 188 | { 189 | "name": "stdout", 190 | "output_type": "stream", 191 | "text": [ 192 | "3\n" 193 | ] 194 | } 195 | ], 196 | "source": [ 197 | "## How many keys in the dictionaries\n", 198 | "student ={'name': 'Utkarsh', 'age':20, 'courses':['compsci','maths']}\n", 199 | "print(len(student))" 200 | ] 201 | }, 202 | { 203 | "cell_type": "code", 204 | "execution_count": 5, 205 | "id": "0c134474", 206 | "metadata": {}, 207 | "outputs": [ 208 | { 209 | "name": "stdout", 210 | "output_type": "stream", 211 | "text": [ 212 | "dict_keys(['name', 'age', 'courses'])\n" 213 | ] 214 | } 215 | ], 216 | "source": [ 217 | "## Show keys of a dictionary\n", 218 | "student ={'name': 'Utkarsh', 'age':20, 'courses':['compsci','maths']}\n", 219 | "print(student.keys())" 220 | ] 221 | }, 222 | { 223 | "cell_type": "code", 224 | "execution_count": 6, 225 | "id": "92e2ad17", 226 | "metadata": {}, 227 | "outputs": [ 228 | { 229 | "name": "stdout", 230 | "output_type": "stream", 231 | "text": [ 232 | "dict_items([('name', 'Utkarsh'), ('age', 20), ('courses', ['compsci', 'maths'])])\n" 233 | ] 234 | } 235 | ], 236 | "source": [ 237 | "##Want to see keys and values\n", 238 | "student ={'name': 'Utkarsh', 'age':20, 'courses':['compsci','maths']}\n", 239 | "print(student.items())" 240 | ] 241 | }, 242 | { 243 | "cell_type": "code", 244 | "execution_count": 7, 245 | "id": "daf0aabc", 246 | "metadata": {}, 247 | "outputs": [ 248 | { 249 | "name": "stdout", 250 | "output_type": "stream", 251 | "text": [ 252 | "dict_values(['Utkarsh', 20, ['compsci', 'maths']])\n" 253 | ] 254 | } 255 | ], 256 | "source": [ 257 | "##Want to see the values\\\n", 258 | "student ={'name': 'Utkarsh', 'age':20, 'courses':['compsci','maths']}\n", 259 | "print(student.values())" 260 | ] 261 | }, 262 | { 263 | "cell_type": "code", 264 | "execution_count": 8, 265 | "id": "3f4c78b6", 266 | "metadata": {}, 267 | "outputs": [ 268 | { 269 | "name": "stdout", 270 | "output_type": "stream", 271 | "text": [ 272 | "name\n", 273 | "age\n", 274 | "courses\n" 275 | ] 276 | } 277 | ], 278 | "source": [ 279 | "##Loop through all the keys \n", 280 | "student ={'name': 'Utkarsh', 'age':20, 'courses':['compsci','maths']}\n", 281 | "for key in student:\n", 282 | " print(key)" 283 | ] 284 | }, 285 | { 286 | "cell_type": "code", 287 | "execution_count": 10, 288 | "id": "4359c617", 289 | "metadata": {}, 290 | "outputs": [ 291 | { 292 | "name": "stdout", 293 | "output_type": "stream", 294 | "text": [ 295 | "('name', 'Utkarsh')\n", 296 | "('age', 20)\n", 297 | "('courses', ['compsci', 'maths'])\n" 298 | ] 299 | } 300 | ], 301 | "source": [ 302 | "##Loop through all the keys and values\n", 303 | "student ={'name': 'Utkarsh', 'age':20, 'courses':['compsci','maths']}\n", 304 | "for key in student.items():\n", 305 | " print(key)" 306 | ] 307 | }, 308 | { 309 | "cell_type": "code", 310 | "execution_count": 13, 311 | "id": "d83031c8", 312 | "metadata": {}, 313 | "outputs": [ 314 | { 315 | "name": "stdout", 316 | "output_type": "stream", 317 | "text": [ 318 | "name Utkarsh\n", 319 | "age 20\n", 320 | "courses ['compsci', 'maths']\n" 321 | ] 322 | } 323 | ], 324 | "source": [ 325 | "##Loop through all the keys and values 2nd\n", 326 | "student ={'name': 'Utkarsh', 'age':20, 'courses':['compsci','maths']}\n", 327 | "for key,value in student.items():\n", 328 | " print(key , value)" 329 | ] 330 | }, 331 | { 332 | "cell_type": "code", 333 | "execution_count": null, 334 | "id": "005788b0", 335 | "metadata": {}, 336 | "outputs": [], 337 | "source": [] 338 | } 339 | ], 340 | "metadata": { 341 | "kernelspec": { 342 | "display_name": "Python 3 (ipykernel)", 343 | "language": "python", 344 | "name": "python3" 345 | }, 346 | "language_info": { 347 | "codemirror_mode": { 348 | "name": "ipython", 349 | "version": 3 350 | }, 351 | "file_extension": ".py", 352 | "mimetype": "text/x-python", 353 | "name": "python", 354 | "nbconvert_exporter": "python", 355 | "pygments_lexer": "ipython3", 356 | "version": "3.10.9" 357 | } 358 | }, 359 | "nbformat": 4, 360 | "nbformat_minor": 5 361 | } 362 | -------------------------------------------------------------------------------- /notebooks/Exception handling .ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "88b8d337", 6 | "metadata": {}, 7 | "source": [ 8 | "### There are 2 stages where error may happen in a program\n", 9 | "\n", 10 | "- During compilation -> Syntax error\n", 11 | "- During execution -> Exceeptions" 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "id": "61f7a3a4", 17 | "metadata": {}, 18 | "source": [ 19 | "### Syntax Error\n", 20 | "\n", 21 | "- Something in the program is not written according to the program grammar.\n", 22 | "- Error is raised by the interpreter/compiler\n", 23 | "- You can solve it by rectifying the program\n" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 2, 29 | "id": "29b574d3", 30 | "metadata": {}, 31 | "outputs": [ 32 | { 33 | "ename": "SyntaxError", 34 | "evalue": "Missing parentheses in call to 'print'. Did you mean print(...)? (528539990.py, line 2)", 35 | "output_type": "error", 36 | "traceback": [ 37 | "\u001b[1;36m Cell \u001b[1;32mIn[2], line 2\u001b[1;36m\u001b[0m\n\u001b[1;33m print 'hello world'\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m Missing parentheses in call to 'print'. Did you mean print(...)?\n" 38 | ] 39 | } 40 | ], 41 | "source": [ 42 | "# Examples of syntax error\n", 43 | "print 'hello world'" 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "id": "4c7ae1ad", 49 | "metadata": {}, 50 | "source": [ 51 | "### Other examples of syntax error\n", 52 | "\n", 53 | "- Leaving symbols like colon,brackets\n", 54 | "- Misspelling a keyword\n", 55 | "- Incorrect indentation\n", 56 | "- empty if/else/loops/class/functions" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 4, 62 | "id": "20ee3050", 63 | "metadata": {}, 64 | "outputs": [ 65 | { 66 | "ename": "SyntaxError", 67 | "evalue": "expected ':' (3315782095.py, line 2)", 68 | "output_type": "error", 69 | "traceback": [ 70 | "\u001b[1;36m Cell \u001b[1;32mIn[4], line 2\u001b[1;36m\u001b[0m\n\u001b[1;33m if a==3\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m expected ':'\n" 71 | ] 72 | } 73 | ], 74 | "source": [ 75 | "a = 5\n", 76 | "if a==3\n", 77 | " print('hello')" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 5, 83 | "id": "a582df90", 84 | "metadata": {}, 85 | "outputs": [ 86 | { 87 | "ename": "SyntaxError", 88 | "evalue": "invalid syntax (521424995.py, line 2)", 89 | "output_type": "error", 90 | "traceback": [ 91 | "\u001b[1;36m Cell \u001b[1;32mIn[5], line 2\u001b[1;36m\u001b[0m\n\u001b[1;33m iff a==3:\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" 92 | ] 93 | } 94 | ], 95 | "source": [ 96 | "a = 5\n", 97 | "iff a==3:\n", 98 | " print('hello')" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": 6, 104 | "id": "dfb1535c", 105 | "metadata": {}, 106 | "outputs": [ 107 | { 108 | "ename": "IndentationError", 109 | "evalue": "expected an indented block after 'if' statement on line 2 (3610895221.py, line 3)", 110 | "output_type": "error", 111 | "traceback": [ 112 | "\u001b[1;36m Cell \u001b[1;32mIn[6], line 3\u001b[1;36m\u001b[0m\n\u001b[1;33m print('hello')\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m expected an indented block after 'if' statement on line 2\n" 113 | ] 114 | } 115 | ], 116 | "source": [ 117 | "a = 5\n", 118 | "if a==3:\n", 119 | "print('hello')" 120 | ] 121 | }, 122 | { 123 | "cell_type": "code", 124 | "execution_count": 7, 125 | "id": "f50206d2", 126 | "metadata": {}, 127 | "outputs": [ 128 | { 129 | "ename": "IndexError", 130 | "evalue": "list index out of range", 131 | "output_type": "error", 132 | "traceback": [ 133 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 134 | "\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)", 135 | "Cell \u001b[1;32mIn[7], line 4\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# IndexError\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;66;03m# The IndexError is thrown when trying to access an item at an invalid index.\u001b[39;00m\n\u001b[0;32m 3\u001b[0m L \u001b[38;5;241m=\u001b[39m [\u001b[38;5;241m1\u001b[39m,\u001b[38;5;241m2\u001b[39m,\u001b[38;5;241m3\u001b[39m]\n\u001b[1;32m----> 4\u001b[0m \u001b[43mL\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m100\u001b[39;49m\u001b[43m]\u001b[49m\n", 136 | "\u001b[1;31mIndexError\u001b[0m: list index out of range" 137 | ] 138 | } 139 | ], 140 | "source": [ 141 | "# IndexError\n", 142 | "# The IndexError is thrown when trying to access an item at an invalid index.\n", 143 | "L = [1,2,3]\n", 144 | "L[100]" 145 | ] 146 | }, 147 | { 148 | "cell_type": "code", 149 | "execution_count": 8, 150 | "id": "96b7cee8", 151 | "metadata": {}, 152 | "outputs": [ 153 | { 154 | "ename": "ModuleNotFoundError", 155 | "evalue": "No module named 'mathi'", 156 | "output_type": "error", 157 | "traceback": [ 158 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 159 | "\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", 160 | "Cell \u001b[1;32mIn[8], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# ModuleNotFoundError\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;66;03m# The ModuleNotFoundError is thrown when a module could not be found.\u001b[39;00m\n\u001b[1;32m----> 3\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mmathi\u001b[39;00m\n\u001b[0;32m 4\u001b[0m math\u001b[38;5;241m.\u001b[39mfloor(\u001b[38;5;241m5.3\u001b[39m)\n", 161 | "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'mathi'" 162 | ] 163 | } 164 | ], 165 | "source": [ 166 | "# ModuleNotFoundError\n", 167 | "# The ModuleNotFoundError is thrown when a module could not be found.\n", 168 | "import mathi\n", 169 | "math.floor(5.3)" 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": 10, 175 | "id": "ee93a463", 176 | "metadata": {}, 177 | "outputs": [ 178 | { 179 | "ename": "KeyError", 180 | "evalue": "'age'", 181 | "output_type": "error", 182 | "traceback": [ 183 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 184 | "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)", 185 | "Cell \u001b[1;32mIn[10], line 5\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# KeyError\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;66;03m# The KeyError is thrown when a key is not found\u001b[39;00m\n\u001b[0;32m 4\u001b[0m d \u001b[38;5;241m=\u001b[39m {\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mname\u001b[39m\u001b[38;5;124m'\u001b[39m:\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mUtkarsh\u001b[39m\u001b[38;5;124m'\u001b[39m}\n\u001b[1;32m----> 5\u001b[0m \u001b[43md\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mage\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\n", 186 | "\u001b[1;31mKeyError\u001b[0m: 'age'" 187 | ] 188 | } 189 | ], 190 | "source": [ 191 | "# KeyError\n", 192 | "# The KeyError is thrown when a key is not found\n", 193 | "\n", 194 | "d = {'name':'Utkarsh'}\n", 195 | "d['age']" 196 | ] 197 | }, 198 | { 199 | "cell_type": "code", 200 | "execution_count": 11, 201 | "id": "df26bbe0", 202 | "metadata": { 203 | "scrolled": true 204 | }, 205 | "outputs": [ 206 | { 207 | "ename": "TypeError", 208 | "evalue": "unsupported operand type(s) for +: 'int' and 'str'", 209 | "output_type": "error", 210 | "traceback": [ 211 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 212 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 213 | "Cell \u001b[1;32mIn[11], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# TypeError\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;66;03m# The TypeError is thrown when an operation or function is applied to an object of an inappropriate type.\u001b[39;00m\n\u001b[1;32m----> 3\u001b[0m \u001b[38;5;241;43m1\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43ma\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\n", 214 | "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for +: 'int' and 'str'" 215 | ] 216 | } 217 | ], 218 | "source": [ 219 | "# TypeError\n", 220 | "# The TypeError is thrown when an operation or function is applied to an object of an inappropriate type.\n", 221 | "1 + 'a'" 222 | ] 223 | }, 224 | { 225 | "cell_type": "code", 226 | "execution_count": 12, 227 | "id": "cb3ce4a2", 228 | "metadata": {}, 229 | "outputs": [ 230 | { 231 | "ename": "ValueError", 232 | "evalue": "invalid literal for int() with base 10: 'a'", 233 | "output_type": "error", 234 | "traceback": [ 235 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 236 | "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", 237 | "Cell \u001b[1;32mIn[12], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# ValueError\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;66;03m# The ValueError is thrown when a function's argument is of an inappropriate type.\u001b[39;00m\n\u001b[1;32m----> 3\u001b[0m \u001b[38;5;28;43mint\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43ma\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n", 238 | "\u001b[1;31mValueError\u001b[0m: invalid literal for int() with base 10: 'a'" 239 | ] 240 | } 241 | ], 242 | "source": [ 243 | "# ValueError\n", 244 | "# The ValueError is thrown when a function's argument is of an inappropriate type.\n", 245 | "int('a')" 246 | ] 247 | }, 248 | { 249 | "cell_type": "code", 250 | "execution_count": 13, 251 | "id": "36cc6eae", 252 | "metadata": {}, 253 | "outputs": [ 254 | { 255 | "ename": "NameError", 256 | "evalue": "name 'k' is not defined", 257 | "output_type": "error", 258 | "traceback": [ 259 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 260 | "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", 261 | "Cell \u001b[1;32mIn[13], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# NameError\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;66;03m# The NameError is thrown when an object could not be found.\u001b[39;00m\n\u001b[1;32m----> 3\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43mk\u001b[49m)\n", 262 | "\u001b[1;31mNameError\u001b[0m: name 'k' is not defined" 263 | ] 264 | } 265 | ], 266 | "source": [ 267 | "# NameError\n", 268 | "# The NameError is thrown when an object could not be found.\n", 269 | "print(k)" 270 | ] 271 | }, 272 | { 273 | "cell_type": "code", 274 | "execution_count": 14, 275 | "id": "fc12707e", 276 | "metadata": {}, 277 | "outputs": [ 278 | { 279 | "ename": "AttributeError", 280 | "evalue": "'list' object has no attribute 'upper'", 281 | "output_type": "error", 282 | "traceback": [ 283 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 284 | "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", 285 | "Cell \u001b[1;32mIn[14], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# AttributeError\u001b[39;00m\n\u001b[0;32m 2\u001b[0m L \u001b[38;5;241m=\u001b[39m [\u001b[38;5;241m1\u001b[39m,\u001b[38;5;241m2\u001b[39m,\u001b[38;5;241m3\u001b[39m]\n\u001b[1;32m----> 3\u001b[0m \u001b[43mL\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mupper\u001b[49m()\n", 286 | "\u001b[1;31mAttributeError\u001b[0m: 'list' object has no attribute 'upper'" 287 | ] 288 | } 289 | ], 290 | "source": [ 291 | "# AttributeError\n", 292 | "L = [1,2,3]\n", 293 | "L.upper()\n", 294 | "\n", 295 | "# Stacktrace" 296 | ] 297 | }, 298 | { 299 | "cell_type": "markdown", 300 | "id": "be3673f8", 301 | "metadata": {}, 302 | "source": [ 303 | "### Exceptions\n", 304 | "\n", 305 | "If things go wrong during the execution of the program(runtime). It generally happens when something unforeseen has happened.\n", 306 | "\n", 307 | "- Exceptions are raised by python runtime\n", 308 | "- You have to takle is on the fly\n", 309 | "\n", 310 | "#### **Examples**\n", 311 | "\n", 312 | "- Memory overflow\n", 313 | "- Divide by 0 -> logical error\n", 314 | "- Database error" 315 | ] 316 | }, 317 | { 318 | "cell_type": "code", 319 | "execution_count": 15, 320 | "id": "91d417b6", 321 | "metadata": {}, 322 | "outputs": [], 323 | "source": [ 324 | "# Why is it important to handle exceptions\n", 325 | "# how to handle exceptions\n", 326 | "# -> Try except block" 327 | ] 328 | }, 329 | { 330 | "cell_type": "code", 331 | "execution_count": 16, 332 | "id": "304be00f", 333 | "metadata": {}, 334 | "outputs": [], 335 | "source": [ 336 | "# let's create a file\n", 337 | "with open('sample.txt','w') as f:\n", 338 | " f.write('hello world')" 339 | ] 340 | }, 341 | { 342 | "cell_type": "code", 343 | "execution_count": 18, 344 | "id": "d0f201b9", 345 | "metadata": {}, 346 | "outputs": [ 347 | { 348 | "name": "stdout", 349 | "output_type": "stream", 350 | "text": [ 351 | "sorry file not found\n" 352 | ] 353 | } 354 | ], 355 | "source": [ 356 | "# try catch demo\n", 357 | "try:\n", 358 | " with open('sample2.txt','r') as f:\n", 359 | " print(f.read())\n", 360 | "except:\n", 361 | " print('sorry file not found')" 362 | ] 363 | }, 364 | { 365 | "cell_type": "code", 366 | "execution_count": 40, 367 | "id": "d73d1c8c", 368 | "metadata": {}, 369 | "outputs": [ 370 | { 371 | "name": "stdout", 372 | "output_type": "stream", 373 | "text": [ 374 | "[Errno 2] No such file or directory: 'sample2.txt'\n" 375 | ] 376 | } 377 | ], 378 | "source": [ 379 | "# catching specific exception\n", 380 | "try:\n", 381 | " f = open('sample2.txt','r')\n", 382 | " print(f.read())\n", 383 | " print(m)\n", 384 | "#except Exception as e:\n", 385 | " #print(e.with_traceback) # tell which type of error with traceback\n", 386 | " \n", 387 | "#except:\n", 388 | " # print('Some error occured')\n", 389 | " \n", 390 | "except Exception as e:\n", 391 | " print(e)\n", 392 | " " 393 | ] 394 | }, 395 | { 396 | "cell_type": "code", 397 | "execution_count": 42, 398 | "id": "398070f5", 399 | "metadata": {}, 400 | "outputs": [ 401 | { 402 | "name": "stdout", 403 | "output_type": "stream", 404 | "text": [ 405 | "hello world\n", 406 | "5\n", 407 | "2.5\n", 408 | "list index out of range\n" 409 | ] 410 | } 411 | ], 412 | "source": [ 413 | "# catching specific exception\n", 414 | "try:\n", 415 | " m=5\n", 416 | " f = open('sample.txt','r')\n", 417 | " print(f.read())\n", 418 | " print(m)\n", 419 | " print(5/2)\n", 420 | " L = [1,2,3]\n", 421 | " L[100]\n", 422 | "except FileNotFoundError:\n", 423 | " print('file not found')\n", 424 | "except NameError:\n", 425 | " print('variable not defined')\n", 426 | "except ZeroDivisionError:\n", 427 | " print(\"can't divide by 0\")\n", 428 | "except Exception as e: #generic exception\n", 429 | " print(e)" 430 | ] 431 | }, 432 | { 433 | "cell_type": "code", 434 | "execution_count": 3, 435 | "id": "41565898", 436 | "metadata": {}, 437 | "outputs": [ 438 | { 439 | "name": "stdout", 440 | "output_type": "stream", 441 | "text": [ 442 | "Xallo\n" 443 | ] 444 | } 445 | ], 446 | "source": [ 447 | "# else\n", 448 | "try:\n", 449 | " f = open('sample1.txt','r')\n", 450 | "except FileNotFoundError:\n", 451 | " print('file not found')\n", 452 | "except Exception:\n", 453 | " print('Some other error')\n", 454 | "else:\n", 455 | " print(f.read())" 456 | ] 457 | }, 458 | { 459 | "cell_type": "code", 460 | "execution_count": 4, 461 | "id": "a3f4bf41", 462 | "metadata": {}, 463 | "outputs": [ 464 | { 465 | "name": "stdout", 466 | "output_type": "stream", 467 | "text": [ 468 | "Xallo\n", 469 | "It must should be executed\n" 470 | ] 471 | } 472 | ], 473 | "source": [ 474 | "# finally\n", 475 | "# else\n", 476 | "try:\n", 477 | " f = open('sample1.txt','r')\n", 478 | "except FileNotFoundError:\n", 479 | " print('file not found')\n", 480 | "except Exception:\n", 481 | " print('Some other error')\n", 482 | "else:\n", 483 | " print(f.read())\n", 484 | "finally:\n", 485 | " print('It must should be executed')" 486 | ] 487 | }, 488 | { 489 | "cell_type": "code", 490 | "execution_count": 22, 491 | "id": "41ee723f", 492 | "metadata": {}, 493 | "outputs": [], 494 | "source": [ 495 | "# raise Exception\n", 496 | "# In Python programming, exceptions are raised when errors occur at runtime. \n", 497 | "# We can also manually raise exceptions using the raise keyword.\n", 498 | "# We can optionally pass values to the exception to clarify why that exception was raised" 499 | ] 500 | }, 501 | { 502 | "cell_type": "code", 503 | "execution_count": 24, 504 | "id": "be579aef", 505 | "metadata": {}, 506 | "outputs": [ 507 | { 508 | "ename": "ZeroDivisionError", 509 | "evalue": "just trying some stuff", 510 | "output_type": "error", 511 | "traceback": [ 512 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 513 | "\u001b[1;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", 514 | "Cell \u001b[1;32mIn[24], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mZeroDivisionError\u001b[39;00m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mjust trying some stuff\u001b[39m\u001b[38;5;124m'\u001b[39m)\n", 515 | "\u001b[1;31mZeroDivisionError\u001b[0m: just trying some stuff" 516 | ] 517 | } 518 | ], 519 | "source": [ 520 | "raise ZeroDivisionError('just trying some stuff')\n", 521 | "# Java\n", 522 | "# try -> try\n", 523 | "# except -> catch\n", 524 | "# raise -> throw" 525 | ] 526 | }, 527 | { 528 | "cell_type": "code", 529 | "execution_count": 7, 530 | "id": "44f1c605", 531 | "metadata": {}, 532 | "outputs": [ 533 | { 534 | "name": "stdout", 535 | "output_type": "stream", 536 | "text": [ 537 | "You have insufficient balance\n" 538 | ] 539 | } 540 | ], 541 | "source": [ 542 | "class Bank:\n", 543 | "\n", 544 | " def __init__(self,balance):\n", 545 | " self.balance = balance\n", 546 | "\n", 547 | " def withdraw(self,amount):\n", 548 | " if amount < 0:\n", 549 | " raise Exception('amount cannot be -ve')\n", 550 | " if self.balance < amount:\n", 551 | " raise Exception('You have insufficient balance')\n", 552 | " self.balance = self.balance - amount\n", 553 | "\n", 554 | "obj = Bank(10000)\n", 555 | "try:\n", 556 | " obj.withdraw(15000)\n", 557 | "except Exception as e:\n", 558 | " print(e)\n", 559 | "else:\n", 560 | " print(obj.balance)" 561 | ] 562 | }, 563 | { 564 | "cell_type": "code", 565 | "execution_count": 10, 566 | "id": "a1d41c6e", 567 | "metadata": {}, 568 | "outputs": [ 569 | { 570 | "name": "stdout", 571 | "output_type": "stream", 572 | "text": [ 573 | "You have insufficient balance\n" 574 | ] 575 | } 576 | ], 577 | "source": [ 578 | "class MyException(Exception):\n", 579 | " def __init__(self,message):\n", 580 | " print(message)\n", 581 | "\n", 582 | "class Bank:\n", 583 | "\n", 584 | " def __init__(self,balance):\n", 585 | " self.balance = balance\n", 586 | "\n", 587 | " def withdraw(self,amount):\n", 588 | " if amount < 0:\n", 589 | " raise MyException('amount cannot be -ve')\n", 590 | " if self.balance < amount:\n", 591 | " raise MyException('You have insufficient balance')\n", 592 | " self.balance = self.balance - amount\n", 593 | "\n", 594 | "obj = Bank(10000)\n", 595 | "try:\n", 596 | " obj.withdraw(11000)\n", 597 | "except MyException as e:\n", 598 | " pass\n", 599 | "else:\n", 600 | " print(obj.balance)" 601 | ] 602 | }, 603 | { 604 | "attachments": { 605 | "exception_hierarchy.png": { 606 | "image/png": "iVBORw0KGgoAAAANSUhEUgAAAooAAAFjCAYAAAC61ypbAAAACXBIWXMAABclAAAXJgHFyhawAABqFklEQVR42uzdBViT2x8H8PNubGOEhIA0SFgYWJiICSgCinjFVhRFsUBFL3rtLkxUQLEQWwk78IqJAYqIipcSQTHAoDa297/hRaXx/kXq+3keH9m7sZ33955z3u/OAgmapgkAAAAAQFESKAEAAAAAICgCAAAAAIIiAAAAACAoAgAAAACCIgAAAAAgKAIAAAAAgiIAAAAAICgCAAAAAIIiAAAAACAoAgAAAACC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CgCAAAAAAAAYBQBAAAAAAAAAIwiAAAAAAAAAEYRAAAAAAAAAKMIAAAAAAAAgFEEAAAAAAAAwCgCAAAAAAAAYBQBAAAAAAAAMIoAAAAAAAAAGEUAAAAAAAAAjCIAAAAAAAAARhEAAAAAAAAAowgAAAAAAACAUQQAAAAAAAAAMIoAAAAAAABAx/wP+eqAJSBnpWYAAAAASUVORK5CYII=" 607 | } 608 | }, 609 | "cell_type": "markdown", 610 | "id": "44b8492c", 611 | "metadata": {}, 612 | "source": [ 613 | "### Exception hierarchy\n", 614 | "![exception_hierarchy.png](attachment:exception_hierarchy.png)" 615 | ] 616 | }, 617 | { 618 | "cell_type": "code", 619 | "execution_count": 27, 620 | "id": "216d4007", 621 | "metadata": {}, 622 | "outputs": [], 623 | "source": [ 624 | "# creating custom exceptions\n", 625 | "# exception hierarchy in python" 626 | ] 627 | }, 628 | { 629 | "cell_type": "code", 630 | "execution_count": 12, 631 | "id": "7eada6aa", 632 | "metadata": {}, 633 | "outputs": [ 634 | { 635 | "name": "stdout", 636 | "output_type": "stream", 637 | "text": [ 638 | "Your account on threat please protect your device\n", 639 | "logout\n", 640 | "database connection closed\n" 641 | ] 642 | } 643 | ], 644 | "source": [ 645 | "class SecurityError(Exception): # You have to make a class for security error\n", 646 | " #which is subclass of exception\n", 647 | " def __init__(self,message):\n", 648 | " print(message)\n", 649 | "\n", 650 | " def logout(self):\n", 651 | " print('logout form all devices')\n", 652 | "\n", 653 | "class Google:\n", 654 | "\n", 655 | " def __init__(self,name,email,password,device):\n", 656 | " self.name = name\n", 657 | " self.email = email\n", 658 | " self.password = password\n", 659 | " self.device = device\n", 660 | "\n", 661 | " def login(self,email,password,device):\n", 662 | " if device != self.device:\n", 663 | " raise SecurityError('Your account on threat please protect your device')\n", 664 | " if email == self.email and password == self.password:\n", 665 | " print('welcome')\n", 666 | " else:\n", 667 | " print('login error')\n", 668 | "\n", 669 | "\n", 670 | "\n", 671 | "obj = Google('utkarsh','utkarsh32@gmail.com','1234','android')\n", 672 | "\n", 673 | "try:\n", 674 | " obj.login('utkarsh32@gmail.com','1234','windows')\n", 675 | "except SecurityError as e:\n", 676 | " e.logout()\n", 677 | "else:\n", 678 | " print(obj.name)\n", 679 | "finally:\n", 680 | " print('database connection closed')\n", 681 | "\n" 682 | ] 683 | }, 684 | { 685 | "cell_type": "code", 686 | "execution_count": null, 687 | "id": "d4f7c640", 688 | "metadata": {}, 689 | "outputs": [], 690 | "source": [] 691 | } 692 | ], 693 | "metadata": { 694 | "kernelspec": { 695 | "display_name": "Python 3 (ipykernel)", 696 | "language": "python", 697 | "name": "python3" 698 | }, 699 | "language_info": { 700 | "codemirror_mode": { 701 | "name": "ipython", 702 | "version": 3 703 | }, 704 | "file_extension": ".py", 705 | "mimetype": "text/x-python", 706 | "name": "python", 707 | "nbconvert_exporter": "python", 708 | "pygments_lexer": "ipython3", 709 | "version": "3.10.9" 710 | } 711 | }, 712 | "nbformat": 4, 713 | "nbformat_minor": 5 714 | } 715 | -------------------------------------------------------------------------------- /notebooks/File Handling + Serialization & Deserialization-1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "17937739", 6 | "metadata": {}, 7 | "source": [ 8 | "### Theory\n", 9 | "\n", 10 | "##### Types of data used for I/O:\n", 11 | "- Text - '12345' as a sequence of unicode chars\n", 12 | "- Binary - 12345 as a sequence of bytes of its binary equivalent\n", 13 | "\n", 14 | "##### Hence there are 2 file types to deal with\n", 15 | "- Text files - All program files are text files\n", 16 | "- Binary Files - Images,music,video,exe files" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "0a57d7ab", 22 | "metadata": {}, 23 | "source": [ 24 | "### How File I/O is done in most programming languages\n", 25 | "\n", 26 | "- Open a file\n", 27 | "- Read/Write data\n", 28 | "- Close the file" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "id": "a6573d69", 34 | "metadata": {}, 35 | "source": [ 36 | "### Writing to a file" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 4, 42 | "id": "66f1b5ea", 43 | "metadata": {}, 44 | "outputs": [ 45 | { 46 | "ename": "ValueError", 47 | "evalue": "I/O operation on closed file.", 48 | "output_type": "error", 49 | "traceback": [ 50 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 51 | "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", 52 | "Cell \u001b[1;32mIn[4], line 5\u001b[0m\n\u001b[0;32m 3\u001b[0m f\u001b[38;5;241m.\u001b[39mwrite(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mHello World\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m 4\u001b[0m f\u001b[38;5;241m.\u001b[39mclose()\n\u001b[1;32m----> 5\u001b[0m \u001b[43mf\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mwrite\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mhello\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n", 53 | "\u001b[1;31mValueError\u001b[0m: I/O operation on closed file." 54 | ] 55 | } 56 | ], 57 | "source": [ 58 | "# Case 1 - if the file is not present\n", 59 | "f = open('sample.txt','w')\n", 60 | "f.write('Hello World')\n", 61 | "f.close()\n", 62 | "# since file is closed the file will not work\n", 63 | "f.write('hello')" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 8, 69 | "id": "e966b733", 70 | "metadata": {}, 71 | "outputs": [], 72 | "source": [ 73 | "# write multiline strings\n", 74 | "f = open('sample.txt','w')\n", 75 | "f.write('hello world')\n", 76 | "f.write('\\n how are you')\n", 77 | "f.close()" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 9, 83 | "id": "48d2d27f", 84 | "metadata": {}, 85 | "outputs": [], 86 | "source": [ 87 | "# case2- if the file is already present\n", 88 | "f = open('sample.txt','w')\n", 89 | "f.write('Ravikant Jangid')\n", 90 | "f.close()" 91 | ] 92 | }, 93 | { 94 | "cell_type": "markdown", 95 | "id": "e7f1921f", 96 | "metadata": {}, 97 | "source": [ 98 | "How open works?\n", 99 | "https://docs.python.org/3/library/functions.html#open" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": 11, 105 | "id": "697c748b", 106 | "metadata": {}, 107 | "outputs": [], 108 | "source": [ 109 | "# problems with w mode\n", 110 | "#introducing appened mode\n", 111 | "f = open('sample1.txt','a')\n", 112 | "f.write('\\n I am fine')\n", 113 | "f.close()" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": 22, 119 | "id": "1404c21c", 120 | "metadata": {}, 121 | "outputs": [], 122 | "source": [ 123 | "# Write lines\n", 124 | "L = ['hello\\n','h1\\n','how are you\\n','I am fine\\n']\n", 125 | "\n", 126 | "f = open('sample1.txt','w')\n", 127 | "f.writelines(L)\n", 128 | "f.close()" 129 | ] 130 | }, 131 | { 132 | "cell_type": "code", 133 | "execution_count": 23, 134 | "id": "b5c14fd5", 135 | "metadata": {}, 136 | "outputs": [ 137 | { 138 | "name": "stdout", 139 | "output_type": "stream", 140 | "text": [ 141 | "hello\n", 142 | "h1\n", 143 | "how are you\n", 144 | "I am fine\n", 145 | "\n" 146 | ] 147 | } 148 | ], 149 | "source": [ 150 | "# Reading from files\n", 151 | "# -> Using read()\n", 152 | "f =open('sample1.txt','r')\n", 153 | "s =f.read()\n", 154 | "print(s)\n", 155 | "f.close()" 156 | ] 157 | }, 158 | { 159 | "cell_type": "code", 160 | "execution_count": 24, 161 | "id": "9ef4a0e2", 162 | "metadata": {}, 163 | "outputs": [ 164 | { 165 | "name": "stdout", 166 | "output_type": "stream", 167 | "text": [ 168 | "hello\n", 169 | "h1\n", 170 | "h\n" 171 | ] 172 | } 173 | ], 174 | "source": [ 175 | "# reading upto n chars\n", 176 | "f =open('sample1.txt','r')\n", 177 | "s =f.read(10)\n", 178 | "print(s)\n", 179 | "f.close()" 180 | ] 181 | }, 182 | { 183 | "cell_type": "code", 184 | "execution_count": 25, 185 | "id": "b5b61d11", 186 | "metadata": {}, 187 | "outputs": [ 188 | { 189 | "name": "stdout", 190 | "output_type": "stream", 191 | "text": [ 192 | "hello\n", 193 | "h1\n" 194 | ] 195 | } 196 | ], 197 | "source": [ 198 | "#readline() -> To read line by line\n", 199 | "f =open('sample1.txt','r')\n", 200 | "print(f.readline(),end='') #if we not put end then 2line gap will appear one of print fn and other of readline\n", 201 | "print(f.readline(),end='')\n", 202 | "f.close()" 203 | ] 204 | }, 205 | { 206 | "cell_type": "code", 207 | "execution_count": 2, 208 | "id": "6cb0a246", 209 | "metadata": {}, 210 | "outputs": [ 211 | { 212 | "name": "stdout", 213 | "output_type": "stream", 214 | "text": [ 215 | "h1\n", 216 | "\n", 217 | "I am fine\n", 218 | "\n" 219 | ] 220 | }, 221 | { 222 | "data": { 223 | "text/plain": [ 224 | "" 225 | ] 226 | }, 227 | "execution_count": 2, 228 | "metadata": {}, 229 | "output_type": "execute_result" 230 | } 231 | ], 232 | "source": [ 233 | "# reading entire using readline\n", 234 | "f = open('sample1.txt','r')\n", 235 | "\n", 236 | "while f.readline() != '':\n", 237 | " print(f.readline())\n", 238 | " \n", 239 | "f.close " 240 | ] 241 | }, 242 | { 243 | "cell_type": "code", 244 | "execution_count": 4, 245 | "id": "ea1117b4", 246 | "metadata": {}, 247 | "outputs": [ 248 | { 249 | "name": "stdout", 250 | "output_type": "stream", 251 | "text": [ 252 | "hello\n", 253 | "h1\n", 254 | "how are you\n", 255 | "I am fine\n" 256 | ] 257 | } 258 | ], 259 | "source": [ 260 | "# reading entire using readline\n", 261 | "f = open('sample1.txt','r')\n", 262 | "\n", 263 | "while True:\n", 264 | "\n", 265 | " data = f.readline()\n", 266 | "\n", 267 | " if data == '':\n", 268 | " break\n", 269 | " else:\n", 270 | " print(data,end='')\n", 271 | "\n", 272 | "f.close()" 273 | ] 274 | }, 275 | { 276 | "cell_type": "markdown", 277 | "id": "f528da9c", 278 | "metadata": {}, 279 | "source": [ 280 | "### Using Context Manager (With)\n", 281 | "\n", 282 | "- It's a good idea to close a file after usage as it will free up the resources\n", 283 | "- If we dont close it, garbage collector would close it\n", 284 | "- with keyword closes the file as soon as the usage is over" 285 | ] 286 | }, 287 | { 288 | "cell_type": "code", 289 | "execution_count": 9, 290 | "id": "5acbaeae", 291 | "metadata": {}, 292 | "outputs": [], 293 | "source": [ 294 | "# with\n", 295 | "with open('sample1.txt','w') as f:\n", 296 | " f.write('selmon bhai')" 297 | ] 298 | }, 299 | { 300 | "cell_type": "code", 301 | "execution_count": 8, 302 | "id": "4595bb31", 303 | "metadata": {}, 304 | "outputs": [ 305 | { 306 | "ename": "ValueError", 307 | "evalue": "I/O operation on closed file.", 308 | "output_type": "error", 309 | "traceback": [ 310 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 311 | "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", 312 | "Cell \u001b[1;32mIn[8], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mf\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mwrite\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mhello\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n", 313 | "\u001b[1;31mValueError\u001b[0m: I/O operation on closed file." 314 | ] 315 | } 316 | ], 317 | "source": [ 318 | "f.write('hello')" 319 | ] 320 | }, 321 | { 322 | "cell_type": "code", 323 | "execution_count": 11, 324 | "id": "d0d83297", 325 | "metadata": {}, 326 | "outputs": [ 327 | { 328 | "name": "stdout", 329 | "output_type": "stream", 330 | "text": [ 331 | "selmon bhai\n" 332 | ] 333 | } 334 | ], 335 | "source": [ 336 | " # try f.read() now\n", 337 | "with open('sample1.txt','r') as f:\n", 338 | " print(f.readline())" 339 | ] 340 | }, 341 | { 342 | "cell_type": "code", 343 | "execution_count": 12, 344 | "id": "01c40d00", 345 | "metadata": {}, 346 | "outputs": [ 347 | { 348 | "name": "stdout", 349 | "output_type": "stream", 350 | "text": [ 351 | "Ravikant J\n", 352 | "angid\n", 353 | "\n", 354 | "\n" 355 | ] 356 | } 357 | ], 358 | "source": [ 359 | "# moving within a file -> 10 char then 10 char\n", 360 | "with open('sample.txt','r') as f:\n", 361 | " print(f.read(10))\n", 362 | " print(f.read(10))\n", 363 | " print(f.read(10))\n", 364 | " print(f.read(10))" 365 | ] 366 | }, 367 | { 368 | "cell_type": "code", 369 | "execution_count": 13, 370 | "id": "b5cb19f6", 371 | "metadata": {}, 372 | "outputs": [], 373 | "source": [ 374 | "# benefit? -> to load a big file in memory\n", 375 | "big_L = ['hello world ' for i in range(1000)]\n", 376 | "\n", 377 | "with open('big.txt','w') as f:\n", 378 | " f.writelines(big_L)\n" 379 | ] 380 | }, 381 | { 382 | "cell_type": "code", 383 | "execution_count": 14, 384 | "id": "d0ae87a2", 385 | "metadata": { 386 | "scrolled": true 387 | }, 388 | "outputs": [ 389 | { 390 | "name": "stdout", 391 | "output_type": "stream", 392 | "text": [ 393 | "d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***d hello wo***o world he***" 394 | ] 395 | } 396 | ], 397 | "source": [ 398 | "with open('big.txt','r') as f:\n", 399 | "\n", 400 | " chunk_size = 10\n", 401 | "\n", 402 | " while len(f.read(chunk_size)) > 0:\n", 403 | " print(f.read(chunk_size),end='***')\n", 404 | " f.read(chunk_size)" 405 | ] 406 | }, 407 | { 408 | "cell_type": "code", 409 | "execution_count": 2, 410 | "id": "1016f858", 411 | "metadata": { 412 | "scrolled": true 413 | }, 414 | "outputs": [ 415 | { 416 | "name": "stdout", 417 | "output_type": "stream", 418 | "text": [ 419 | "hyay \n", 420 | "My n\n", 421 | "25\n", 422 | "ame is rav\n", 423 | "35\n" 424 | ] 425 | } 426 | ], 427 | "source": [ 428 | "# seek and tell function\n", 429 | "with open('sample1.txt','r') as f:\n", 430 | " f.seek(15)\n", 431 | " print(f.read(10))\n", 432 | " print(f.tell()) #gives you idea about on which char you're on \n", 433 | " \n", 434 | " print(f.read(10))\n", 435 | " print(f.tell())" 436 | ] 437 | }, 438 | { 439 | "cell_type": "code", 440 | "execution_count": 7, 441 | "id": "0f1e549e", 442 | "metadata": {}, 443 | "outputs": [], 444 | "source": [ 445 | "# seek during write\n", 446 | "with open('sample.txt','w') as f:\n", 447 | " f.write('Hello')\n", 448 | " f.seek(0) #seek can move your cursor at any character like here 0 \n", 449 | " f.write('X')" 450 | ] 451 | }, 452 | { 453 | "cell_type": "markdown", 454 | "id": "7e5a59ac", 455 | "metadata": {}, 456 | "source": [ 457 | "### Problems with working in text mode\n", 458 | "\n", 459 | "- can't work with binary files like images\n", 460 | "- not good for other data types like int/float/list/tuples" 461 | ] 462 | }, 463 | { 464 | "cell_type": "code", 465 | "execution_count": 8, 466 | "id": "1eb14343", 467 | "metadata": {}, 468 | "outputs": [ 469 | { 470 | "ename": "UnicodeDecodeError", 471 | "evalue": "'charmap' codec can't decode byte 0x81 in position 248: character maps to ", 472 | "output_type": "error", 473 | "traceback": [ 474 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 475 | "\u001b[1;31mUnicodeDecodeError\u001b[0m Traceback (most recent call last)", 476 | "Cell \u001b[1;32mIn[8], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# working with binary file\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mopen\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mphoto_2.jpg\u001b[39m\u001b[38;5;124m'\u001b[39m,\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mr\u001b[39m\u001b[38;5;124m'\u001b[39m) \u001b[38;5;28;01mas\u001b[39;00m f:\n\u001b[1;32m----> 3\u001b[0m \u001b[43mf\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mread\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", 477 | "File \u001b[1;32m~\\anaconda3\\lib\\encodings\\cp1252.py:23\u001b[0m, in \u001b[0;36mIncrementalDecoder.decode\u001b[1;34m(self, input, final)\u001b[0m\n\u001b[0;32m 22\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mdecode\u001b[39m(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;28minput\u001b[39m, final\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m):\n\u001b[1;32m---> 23\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mcodecs\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcharmap_decode\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43merrors\u001b[49m\u001b[43m,\u001b[49m\u001b[43mdecoding_table\u001b[49m\u001b[43m)\u001b[49m[\u001b[38;5;241m0\u001b[39m]\n", 478 | "\u001b[1;31mUnicodeDecodeError\u001b[0m: 'charmap' codec can't decode byte 0x81 in position 248: character maps to " 479 | ] 480 | } 481 | ], 482 | "source": [ 483 | "# working with binary file\n", 484 | "with open('photo_2.jpg','r') as f:\n", 485 | " f.read()" 486 | ] 487 | }, 488 | { 489 | "cell_type": "code", 490 | "execution_count": 9, 491 | "id": "0843a952", 492 | "metadata": {}, 493 | "outputs": [], 494 | "source": [ 495 | "# working with binary file\n", 496 | "with open('photo_2.jpg','rb') as f: #read binary -> rb\n", 497 | " with open('photo_2copy.jpg','wb') as wf:\n", 498 | " wf.write(f.read())" 499 | ] 500 | }, 501 | { 502 | "cell_type": "code", 503 | "execution_count": 20, 504 | "id": "b12bfe09", 505 | "metadata": {}, 506 | "outputs": [], 507 | "source": [ 508 | "# working with a big binary file" 509 | ] 510 | }, 511 | { 512 | "cell_type": "code", 513 | "execution_count": 10, 514 | "id": "a9410080", 515 | "metadata": { 516 | "scrolled": true 517 | }, 518 | "outputs": [ 519 | { 520 | "ename": "TypeError", 521 | "evalue": "write() argument must be str, not int", 522 | "output_type": "error", 523 | "traceback": [ 524 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 525 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 526 | "Cell \u001b[1;32mIn[10], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# working with other data types\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mopen\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124msample.txt\u001b[39m\u001b[38;5;124m'\u001b[39m,\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mw\u001b[39m\u001b[38;5;124m'\u001b[39m) \u001b[38;5;28;01mas\u001b[39;00m f:\n\u001b[1;32m----> 3\u001b[0m \u001b[43mf\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mwrite\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m5\u001b[39;49m\u001b[43m)\u001b[49m\n", 527 | "\u001b[1;31mTypeError\u001b[0m: write() argument must be str, not int" 528 | ] 529 | } 530 | ], 531 | "source": [ 532 | "# working with other data types\n", 533 | "with open('sample.txt','w') as f:\n", 534 | " f.write(5) #you can't write another datatype" 535 | ] 536 | }, 537 | { 538 | "cell_type": "code", 539 | "execution_count": 22, 540 | "id": "99cc7cd0", 541 | "metadata": {}, 542 | "outputs": [], 543 | "source": [ 544 | "with open('sample.txt','w') as f:\n", 545 | " f.write('5')" 546 | ] 547 | }, 548 | { 549 | "cell_type": "code", 550 | "execution_count": 23, 551 | "id": "ed4726d8", 552 | "metadata": {}, 553 | "outputs": [ 554 | { 555 | "name": "stdout", 556 | "output_type": "stream", 557 | "text": [ 558 | "10\n" 559 | ] 560 | } 561 | ], 562 | "source": [ 563 | "with open('sample.txt','r') as f:\n", 564 | " print(int(f.read()) + 5)" 565 | ] 566 | }, 567 | { 568 | "cell_type": "code", 569 | "execution_count": 16, 570 | "id": "ddd184e5", 571 | "metadata": {}, 572 | "outputs": [], 573 | "source": [ 574 | "# more complex data\n", 575 | "d = {\n", 576 | " 'name':'Utkarsh',\n", 577 | " 'age':20,\n", 578 | " 'gender':'male'\n", 579 | "}\n", 580 | "\n", 581 | "with open('sample.txt','w') as f:\n", 582 | " f.write(str(d))" 583 | ] 584 | }, 585 | { 586 | "cell_type": "code", 587 | "execution_count": 20, 588 | "id": "9cf3f35b", 589 | "metadata": {}, 590 | "outputs": [ 591 | { 592 | "ename": "ValueError", 593 | "evalue": "dictionary update sequence element #0 has length 1; 2 is required", 594 | "output_type": "error", 595 | "traceback": [ 596 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 597 | "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", 598 | "Cell \u001b[1;32mIn[20], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mopen\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124msample.txt\u001b[39m\u001b[38;5;124m'\u001b[39m,\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mr\u001b[39m\u001b[38;5;124m'\u001b[39m) \u001b[38;5;28;01mas\u001b[39;00m f:\n\u001b[0;32m 2\u001b[0m \u001b[38;5;66;03m#print(f.read())\u001b[39;00m\n\u001b[1;32m----> 3\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28;43mdict\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mf\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mread\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m)\n", 599 | "\u001b[1;31mValueError\u001b[0m: dictionary update sequence element #0 has length 1; 2 is required" 600 | ] 601 | } 602 | ], 603 | "source": [ 604 | "with open('sample.txt','r') as f:\n", 605 | " #print(f.read())\n", 606 | " print(dict(f.read()))" 607 | ] 608 | }, 609 | { 610 | "cell_type": "code", 611 | "execution_count": 21, 612 | "id": "f889ff5a", 613 | "metadata": {}, 614 | "outputs": [], 615 | "source": [ 616 | "# So above problem is solve using serialisation and deserialisation" 617 | ] 618 | }, 619 | { 620 | "cell_type": "code", 621 | "execution_count": null, 622 | "id": "70cac7c2", 623 | "metadata": {}, 624 | "outputs": [], 625 | "source": [] 626 | } 627 | ], 628 | "metadata": { 629 | "kernelspec": { 630 | "display_name": "Python 3 (ipykernel)", 631 | "language": "python", 632 | "name": "python3" 633 | }, 634 | "language_info": { 635 | "codemirror_mode": { 636 | "name": "ipython", 637 | "version": 3 638 | }, 639 | "file_extension": ".py", 640 | "mimetype": "text/x-python", 641 | "name": "python", 642 | "nbconvert_exporter": "python", 643 | "pygments_lexer": "ipython3", 644 | "version": "3.10.9" 645 | } 646 | }, 647 | "nbformat": 4, 648 | "nbformat_minor": 5 649 | } 650 | -------------------------------------------------------------------------------- /notebooks/File Handling + Serialization & Deserialization-2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "9031e868", 6 | "metadata": {}, 7 | "source": [ 8 | "### Serialization and Deserialization\n", 9 | "\n", 10 | "- **Serialization** - process of converting python data types to JSON format\n", 11 | "- **Deserialization** - process of converting JSON to python data types\n", 12 | "\n", 13 | "#### What is JSON?\n" 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": 1, 19 | "id": "b928fdd5", 20 | "metadata": {}, 21 | "outputs": [], 22 | "source": [ 23 | "# javascript object notation\n", 24 | "# It is a universal datatypes which is understood by every lang" 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": 2, 30 | "id": "d19912fa", 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "# serialization using json module\n", 35 | "# list\n", 36 | "import json\n", 37 | "\n", 38 | "L = [1,2,3,4]\n", 39 | "\n", 40 | "with open('demo.json','w') as f:\n", 41 | " json.dump(L,f) #dump put in the file -> dumps convert it into string\n" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": 3, 47 | "id": "2af41892", 48 | "metadata": {}, 49 | "outputs": [], 50 | "source": [ 51 | "# dict\n", 52 | "d = {\n", 53 | " 'name':'Utkarsh',\n", 54 | " 'age':20,\n", 55 | " 'gender':'male'\n", 56 | "}\n", 57 | "\n", 58 | "with open('demo.json','w') as f:\n", 59 | " json.dump(d,f,indent=4)" 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": 4, 65 | "id": "d6f10718", 66 | "metadata": {}, 67 | "outputs": [ 68 | { 69 | "name": "stdout", 70 | "output_type": "stream", 71 | "text": [ 72 | "{'name': 'Utkarsh', 'age': 20, 'gender': 'male'}\n", 73 | "\n" 74 | ] 75 | } 76 | ], 77 | "source": [ 78 | "# deserialization\n", 79 | "import json\n", 80 | "\n", 81 | "with open('demo.json','r') as f:\n", 82 | " d = json.load(f)\n", 83 | " print(d)\n", 84 | " print(type(d))" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": 5, 90 | "id": "bb023fbb", 91 | "metadata": {}, 92 | "outputs": [], 93 | "source": [ 94 | "# serialize and deserialize tuple\n", 95 | "import json\n", 96 | "\n", 97 | "t = (1,2,3,4,5)\n", 98 | "\n", 99 | "with open('demo.json','w') as f:\n", 100 | " json.dump(t,f)" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": 6, 106 | "id": "6c2bb128", 107 | "metadata": {}, 108 | "outputs": [], 109 | "source": [ 110 | "# serialize and deserialize a nested dict\n", 111 | "\n", 112 | "d = {\n", 113 | " 'student':'Utkarsh',\n", 114 | " 'marks':[23,14,34,45,56]\n", 115 | "}\n", 116 | "\n", 117 | "with open('demo.json','w') as f:\n", 118 | " json.dump(d,f)" 119 | ] 120 | }, 121 | { 122 | "cell_type": "markdown", 123 | "id": "64eb6086", 124 | "metadata": {}, 125 | "source": [ 126 | "### Serializing and Deserializing custom objects" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": 7, 132 | "id": "2f3d4cbd", 133 | "metadata": {}, 134 | "outputs": [], 135 | "source": [ 136 | "class Person:\n", 137 | "\n", 138 | " def __init__(self,fname,lname,age,gender):\n", 139 | " self.fname = fname\n", 140 | " self.lname = lname\n", 141 | " self.age = age\n", 142 | " self.gender = gender\n", 143 | "\n", 144 | "# format to printed in\n", 145 | "# -> Utkarsh Upadhyay age -> 20 gender -> male" 146 | ] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "execution_count": 8, 151 | "id": "077a6c05", 152 | "metadata": {}, 153 | "outputs": [], 154 | "source": [ 155 | "person = Person('Utkarsh','Upadhyay',20,'male')" 156 | ] 157 | }, 158 | { 159 | "cell_type": "code", 160 | "execution_count": 9, 161 | "id": "9de4e7de", 162 | "metadata": {}, 163 | "outputs": [], 164 | "source": [ 165 | "# As a string\n", 166 | "import json\n", 167 | "\n", 168 | "def show_object(person):\n", 169 | " if isinstance(person,Person):\n", 170 | " return \"{} {} age -> {} gender -> {}\".format(person.fname,person.lname,person.age,person.gender)\n", 171 | "\n", 172 | "with open('demo.json','w') as f:\n", 173 | " json.dump(person,f,default=show_object)" 174 | ] 175 | }, 176 | { 177 | "cell_type": "code", 178 | "execution_count": 10, 179 | "id": "97998af5", 180 | "metadata": {}, 181 | "outputs": [], 182 | "source": [ 183 | "# As a dict\n", 184 | "import json\n", 185 | "\n", 186 | "def show_object(person):\n", 187 | " if isinstance(person,Person):\n", 188 | " return {'name':person.fname + ' ' + person.lname,'age':person.age,'gender':person.gender}\n", 189 | "\n", 190 | "with open('demo.json','w') as f:\n", 191 | " json.dump(person,f,default=show_object,indent=4)" 192 | ] 193 | }, 194 | { 195 | "cell_type": "code", 196 | "execution_count": 11, 197 | "id": "5bb46473", 198 | "metadata": {}, 199 | "outputs": [], 200 | "source": [ 201 | "# indent arrtribute\n", 202 | "# As a dict" 203 | ] 204 | }, 205 | { 206 | "cell_type": "code", 207 | "execution_count": 12, 208 | "id": "2e9fa0e6", 209 | "metadata": {}, 210 | "outputs": [ 211 | { 212 | "name": "stdout", 213 | "output_type": "stream", 214 | "text": [ 215 | "{'name': 'Utkarsh Upadhyay', 'age': 20, 'gender': 'male'}\n", 216 | "\n" 217 | ] 218 | } 219 | ], 220 | "source": [ 221 | "# deserializing\n", 222 | "import json\n", 223 | "\n", 224 | "with open('demo.json','r') as f:\n", 225 | " d = json.load(f)\n", 226 | " print(d)\n", 227 | " print(type(d))" 228 | ] 229 | }, 230 | { 231 | "cell_type": "markdown", 232 | "id": "b1ebe95d", 233 | "metadata": {}, 234 | "source": [ 235 | "### Pickling\n", 236 | "`Pickling` is the process whereby a Python object hierarchy is converted into a byte stream, and `unpickling` is the inverse operation, whereby a byte stream (from a binary file or bytes-like object) is converted back into an object hierarchy." 237 | ] 238 | }, 239 | { 240 | "cell_type": "code", 241 | "execution_count": 13, 242 | "id": "6065e7a4", 243 | "metadata": {}, 244 | "outputs": [], 245 | "source": [ 246 | "class Person:\n", 247 | "\n", 248 | " def __init__(self,name,age):\n", 249 | " self.name = name\n", 250 | " self.age = age\n", 251 | "\n", 252 | " def display_info(self):\n", 253 | " print('Hi my name is',self.name,'and I am ',self.age,'years old')" 254 | ] 255 | }, 256 | { 257 | "cell_type": "code", 258 | "execution_count": 14, 259 | "id": "21ed8a1f", 260 | "metadata": {}, 261 | "outputs": [], 262 | "source": [ 263 | "p = Person('Utkarsh',20)\n" 264 | ] 265 | }, 266 | { 267 | "cell_type": "code", 268 | "execution_count": 15, 269 | "id": "fa5e49c0", 270 | "metadata": {}, 271 | "outputs": [], 272 | "source": [ 273 | "# pickle dump\n", 274 | "import pickle\n", 275 | "with open('person.pkl','wb') as f:\n", 276 | " pickle.dump(p,f)" 277 | ] 278 | }, 279 | { 280 | "cell_type": "code", 281 | "execution_count": 16, 282 | "id": "5540d27f", 283 | "metadata": {}, 284 | "outputs": [ 285 | { 286 | "name": "stdout", 287 | "output_type": "stream", 288 | "text": [ 289 | "Hi my name is Utkarsh and I am 20 years old\n" 290 | ] 291 | } 292 | ], 293 | "source": [ 294 | "# pickle load\n", 295 | "import pickle\n", 296 | "with open('person.pkl','rb') as f:\n", 297 | " p = pickle.load(f)\n", 298 | "\n", 299 | "p.display_info()" 300 | ] 301 | }, 302 | { 303 | "cell_type": "markdown", 304 | "id": "899352d5", 305 | "metadata": {}, 306 | "source": [ 307 | "### Pickle Vs Json\n", 308 | "\n", 309 | "- Pickle lets the user to store data in binary format. JSON lets the user store data in a human-readable text format." 310 | ] 311 | }, 312 | { 313 | "cell_type": "code", 314 | "execution_count": null, 315 | "id": "d44a530a", 316 | "metadata": {}, 317 | "outputs": [], 318 | "source": [] 319 | } 320 | ], 321 | "metadata": { 322 | "kernelspec": { 323 | "display_name": "Python 3 (ipykernel)", 324 | "language": "python", 325 | "name": "python3" 326 | }, 327 | "language_info": { 328 | "codemirror_mode": { 329 | "name": "ipython", 330 | "version": 3 331 | }, 332 | "file_extension": ".py", 333 | "mimetype": "text/x-python", 334 | "name": "python", 335 | "nbconvert_exporter": "python", 336 | "pygments_lexer": "ipython3", 337 | "version": "3.10.9" 338 | } 339 | }, 340 | "nbformat": 4, 341 | "nbformat_minor": 5 342 | } 343 | -------------------------------------------------------------------------------- /notebooks/Function.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "513c2f4b", 6 | "metadata": {}, 7 | "source": [ 8 | "# Function\n", 9 | ".py-- is a regular python file. It's plain text and contains just your code.\n", 10 | "\n", 11 | ".ipynb--- is a python notebook and it contains the notebook code, the execution results and other internal settings in a specific format. You can just run .ipynb on the jupyter environment." 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 3, 17 | "id": "845cc133", 18 | "metadata": {}, 19 | "outputs": [ 20 | { 21 | "name": "stdout", 22 | "output_type": "stream", 23 | "text": [ 24 | "None\n" 25 | ] 26 | } 27 | ], 28 | "source": [ 29 | "def hello_func():\n", 30 | " pass ##This keyword is used when we don't use the function \n", 31 | "print(hello_func())" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 4, 37 | "id": "f4567c84", 38 | "metadata": {}, 39 | "outputs": [ 40 | { 41 | "name": "stdout", 42 | "output_type": "stream", 43 | "text": [ 44 | "Hello function!\n" 45 | ] 46 | } 47 | ], 48 | "source": [ 49 | "def hello_func():\n", 50 | " print('Hello function!')\n", 51 | "hello_func() " 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": 5, 57 | "id": "98383693", 58 | "metadata": {}, 59 | "outputs": [ 60 | { 61 | "name": "stdout", 62 | "output_type": "stream", 63 | "text": [ 64 | "HELLO FUNCTION!\n" 65 | ] 66 | } 67 | ], 68 | "source": [ 69 | "def hello_func():\n", 70 | " return 'Hello function!'\n", 71 | " \n", 72 | "print(hello_func().upper())" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": 6, 78 | "id": "67d8c96a", 79 | "metadata": {}, 80 | "outputs": [ 81 | { 82 | "name": "stdout", 83 | "output_type": "stream", 84 | "text": [ 85 | "HI Function.\n" 86 | ] 87 | } 88 | ], 89 | "source": [ 90 | "##Passing a argument in a function\n", 91 | "def hello_func(greeting):\n", 92 | " return '{} Function.'.format(greeting)\n", 93 | "print(hello_func('HI'))" 94 | ] 95 | }, 96 | { 97 | "cell_type": "code", 98 | "execution_count": 7, 99 | "id": "38ba3726", 100 | "metadata": {}, 101 | "outputs": [ 102 | { 103 | "name": "stdout", 104 | "output_type": "stream", 105 | "text": [ 106 | "HI, Utkarsh Function.\n" 107 | ] 108 | } 109 | ], 110 | "source": [ 111 | "def hello_func(greeting, name='Utkarsh'):\n", 112 | " \n", 113 | " return '{}, {} Function.'.format(greeting, name)\n", 114 | "print(hello_func('HI'))" 115 | ] 116 | }, 117 | { 118 | "cell_type": "code", 119 | "execution_count": 8, 120 | "id": "31bb46ed", 121 | "metadata": {}, 122 | "outputs": [ 123 | { 124 | "name": "stdout", 125 | "output_type": "stream", 126 | "text": [ 127 | "HI, Aryan Function.\n" 128 | ] 129 | } 130 | ], 131 | "source": [ 132 | "def hello_func(greeting, name='Utkarsh'):\n", 133 | " \n", 134 | " return '{}, {} Function.'.format(greeting, name)\n", 135 | "print(hello_func('HI','Aryan'))" 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": 9, 141 | "id": "401ba88c", 142 | "metadata": {}, 143 | "outputs": [ 144 | { 145 | "name": "stdout", 146 | "output_type": "stream", 147 | "text": [ 148 | "('Math', 'Art')\n", 149 | "{'name': 'John', 'age': 22}\n" 150 | ] 151 | } 152 | ], 153 | "source": [ 154 | "def hello_func(greeting, name='Utkarsh'):\n", 155 | " \n", 156 | " return '{}, {} Function.'.format(greeting, name)\n", 157 | "#print(hello_func('HI'))\n", 158 | "\n", 159 | "def student_info(*args, **kwargs):\n", 160 | " print(args) ##They basically gives us tupels/lists and keywords/Dictionary (arguments)\n", 161 | " print(kwargs)\n", 162 | " \n", 163 | "student_info('Math','Art',name='John', age=22) " 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": 10, 169 | "id": "615e5dd2", 170 | "metadata": {}, 171 | "outputs": [ 172 | { 173 | "name": "stdout", 174 | "output_type": "stream", 175 | "text": [ 176 | "(['Math', 'Art'], {'name': 'John', 'age': 22})\n", 177 | "{}\n" 178 | ] 179 | } 180 | ], 181 | "source": [ 182 | "\n", 183 | "def student_info(*args, **kwargs):\n", 184 | " print(args) \n", 185 | " print(kwargs)\n", 186 | "\n", 187 | "courses = ['Math', 'Art']\n", 188 | "info = {'name': 'John', 'age':22}\n", 189 | "\n", 190 | "student_info(courses, info) ##Without any *\n" 191 | ] 192 | }, 193 | { 194 | "cell_type": "code", 195 | "execution_count": 11, 196 | "id": "7b58ec13", 197 | "metadata": {}, 198 | "outputs": [ 199 | { 200 | "name": "stdout", 201 | "output_type": "stream", 202 | "text": [ 203 | "('Math', 'Art')\n", 204 | "{'name': 'John', 'age': 22}\n" 205 | ] 206 | } 207 | ], 208 | "source": [ 209 | "\n", 210 | "def student_info(*args, **kwargs):\n", 211 | " print(args) \n", 212 | " print(kwargs)\n", 213 | "\n", 214 | "courses = ['Math', 'Art']\n", 215 | "info = {'name': 'John', 'age':22}\n", 216 | "\n", 217 | "student_info(*courses, **info) ##With *\n" 218 | ] 219 | }, 220 | { 221 | "cell_type": "code", 222 | "execution_count": 5, 223 | "id": "96209773", 224 | "metadata": {}, 225 | "outputs": [ 226 | { 227 | "ename": "IndentationError", 228 | "evalue": "unindent does not match any outer indentation level (, line 9)", 229 | "output_type": "error", 230 | "traceback": [ 231 | "\u001b[1;36m File \u001b[1;32m:9\u001b[1;36m\u001b[0m\n\u001b[1;33m def days_in_month(year,month):\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m unindent does not match any outer indentation level\n" 232 | ] 233 | } 234 | ], 235 | "source": [ 236 | "#Number of Days in a month. First value placeholder for indexing purposes\n", 237 | "month_days = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n", 238 | "\n", 239 | "def is_leap(year):\n", 240 | "\"\"\"Return True for leap year and False for non-leap year\"\"\" ##It's string doc\n", 241 | " \n", 242 | " return year %4 ==0 and (year %100 !=0 or year %400 ==0)\n", 243 | "\n", 244 | " def days_in_month(year,month):\n", 245 | "\"\"\"Returns the number of days in that month in that year \"\"\"\n", 246 | " if not 1<=month <=12:\n", 247 | " return 'Invalid month'\n", 248 | "\n", 249 | " if month ==2 and is_leap(year):\n", 250 | " return 29\n", 251 | " return month_days[month]\n", 252 | " print(is_leap(2017))\n", 253 | "##print(days_in_month(2017, 2))" 254 | ] 255 | }, 256 | { 257 | "cell_type": "code", 258 | "execution_count": null, 259 | "id": "b4789209", 260 | "metadata": {}, 261 | "outputs": [], 262 | "source": [ 263 | "def print_models(unprinted_designs, completed_models):\n", 264 | " \"\"\"Simulate printing in each design, until none is left.\n", 265 | " Move each design to completed_models after printing.\"\"\"\n", 266 | " while unprinted_designs:\n", 267 | " current_designs= unprinted_designs.pop()\n", 268 | " \n", 269 | " #simulate creating a 3D print from the design.\n", 270 | " print(\"Printing model:\" + current_design)\n", 271 | " completed_models.append(current_design)\n", 272 | " def show_completed_models(completed_models):\n", 273 | " for completed_model in completed_models:\n", 274 | " print(completed_model)\n", 275 | " unprinted_designs= ['iphone case','robot pendant','dodecahedron']\n", 276 | " completed_models =[]\n", 277 | " print_models(unprinted_designs, completed_models)\n", 278 | " show_completed_models(completed_models)" 279 | ] 280 | }, 281 | { 282 | "cell_type": "code", 283 | "execution_count": null, 284 | "id": "4641db86", 285 | "metadata": {}, 286 | "outputs": [], 287 | "source": [] 288 | }, 289 | { 290 | "cell_type": "code", 291 | "execution_count": null, 292 | "id": "3ae7f55d", 293 | "metadata": {}, 294 | "outputs": [], 295 | "source": [] 296 | } 297 | ], 298 | "metadata": { 299 | "kernelspec": { 300 | "display_name": "Python 3 (ipykernel)", 301 | "language": "python", 302 | "name": "python3" 303 | }, 304 | "language_info": { 305 | "codemirror_mode": { 306 | "name": "ipython", 307 | "version": 3 308 | }, 309 | "file_extension": ".py", 310 | "mimetype": "text/x-python", 311 | "name": "python", 312 | "nbconvert_exporter": "python", 313 | "pygments_lexer": "ipython3", 314 | "version": "3.10.9" 315 | } 316 | }, 317 | "nbformat": 4, 318 | "nbformat_minor": 5 319 | } 320 | -------------------------------------------------------------------------------- /notebooks/Lambda function.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "e9232a80", 6 | "metadata": {}, 7 | "source": [ 8 | "It is an anonymous function defined without a name and without using a def keyword. It can take only one expression but have multiple arguments." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 19, 14 | "id": "08886e64", 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "def add(a,b):\n", 19 | " result=a+b\n", 20 | " return result" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 20, 26 | "id": "3251842a", 27 | "metadata": {}, 28 | "outputs": [ 29 | { 30 | "data": { 31 | "text/plain": [ 32 | "10" 33 | ] 34 | }, 35 | "execution_count": 20, 36 | "metadata": {}, 37 | "output_type": "execute_result" 38 | } 39 | ], 40 | "source": [ 41 | "add(3,7)" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": 21, 47 | "id": "7b7824ad", 48 | "metadata": {}, 49 | "outputs": [ 50 | { 51 | "data": { 52 | "text/plain": [ 53 | "10" 54 | ] 55 | }, 56 | "execution_count": 21, 57 | "metadata": {}, 58 | "output_type": "execute_result" 59 | } 60 | ], 61 | "source": [ 62 | "add = lambda a,b : a+b ## Syntax lambda arguments: expression\n", 63 | "add(3,7)" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 22, 69 | "id": "d32e1b18", 70 | "metadata": {}, 71 | "outputs": [ 72 | { 73 | "data": { 74 | "text/plain": [ 75 | "82" 76 | ] 77 | }, 78 | "execution_count": 22, 79 | "metadata": {}, 80 | "output_type": "execute_result" 81 | } 82 | ], 83 | "source": [ 84 | "add = lambda a:a+50\n", 85 | "add(32)" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": 23, 91 | "id": "8ef2e754", 92 | "metadata": {}, 93 | "outputs": [ 94 | { 95 | "data": { 96 | "text/plain": [ 97 | "15" 98 | ] 99 | }, 100 | "execution_count": 23, 101 | "metadata": {}, 102 | "output_type": "execute_result" 103 | } 104 | ], 105 | "source": [ 106 | " (lambda a,b:a*b)(5,3)" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": 24, 112 | "id": "d5efba62", 113 | "metadata": {}, 114 | "outputs": [ 115 | { 116 | "name": "stdout", 117 | "output_type": "stream", 118 | "text": [ 119 | "14\n" 120 | ] 121 | } 122 | ], 123 | "source": [ 124 | "###Allow as many args as you want\n", 125 | "addition =lambda *args : sum(args)\n", 126 | "print(addition(2,3,4,5))" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": 25, 132 | "id": "36b90aac", 133 | "metadata": {}, 134 | "outputs": [ 135 | { 136 | "data": { 137 | "text/plain": [ 138 | "420" 139 | ] 140 | }, 141 | "execution_count": 25, 142 | "metadata": {}, 143 | "output_type": "execute_result" 144 | } 145 | ], 146 | "source": [ 147 | "## return one or more function\n", 148 | "higher_ord_fun= lambda x, fun: x+ fun(x)\n", 149 | "higher_ord_fun(20, lambda x:x*x)" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": 26, 155 | "id": "46a2a81e", 156 | "metadata": {}, 157 | "outputs": [ 158 | { 159 | "data": { 160 | "text/plain": [ 161 | "'odd'" 162 | ] 163 | }, 164 | "execution_count": 26, 165 | "metadata": {}, 166 | "output_type": "execute_result" 167 | } 168 | ], 169 | "source": [ 170 | "(lambda x: (x % 2 and 'odd' or 'even') )(45)" 171 | ] 172 | }, 173 | { 174 | "cell_type": "code", 175 | "execution_count": 27, 176 | "id": "b222fe53", 177 | "metadata": {}, 178 | "outputs": [ 179 | { 180 | "name": "stdout", 181 | "output_type": "stream", 182 | "text": [ 183 | "True\n" 184 | ] 185 | } 186 | ], 187 | "source": [ 188 | "cv= lambda string: string in \"Welcome to python lambda functions Tutorial\"\n", 189 | "print(cv('python'))" 190 | ] 191 | }, 192 | { 193 | "cell_type": "code", 194 | "execution_count": 28, 195 | "id": "5377ea4f", 196 | "metadata": { 197 | "scrolled": true 198 | }, 199 | "outputs": [ 200 | { 201 | "name": "stdout", 202 | "output_type": "stream", 203 | "text": [ 204 | "True\n" 205 | ] 206 | } 207 | ], 208 | "source": [ 209 | "cv= lambda string: string in \"Welcome to python lambda functions Tutorial\"\n", 210 | "print(cv('python'))" 211 | ] 212 | }, 213 | { 214 | "cell_type": "code", 215 | "execution_count": 35, 216 | "id": "b505b53d", 217 | "metadata": { 218 | "scrolled": true 219 | }, 220 | "outputs": [ 221 | { 222 | "ename": "TypeError", 223 | "evalue": "'list' object is not callable", 224 | "output_type": "error", 225 | "traceback": [ 226 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 227 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 228 | "Cell \u001b[1;32mIn[35], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m num \u001b[38;5;241m=\u001b[39m [\u001b[38;5;241m19\u001b[39m, \u001b[38;5;241m34\u001b[39m, \u001b[38;5;241m45\u001b[39m, \u001b[38;5;241m23\u001b[39m, \u001b[38;5;241m12\u001b[39m, \u001b[38;5;241m33\u001b[39m]\n\u001b[1;32m----> 2\u001b[0m greater \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mlist\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mfilter\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43;01mlambda\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mnum\u001b[49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mnum\u001b[49m\u001b[38;5;241;43m>\u001b[39;49m\u001b[38;5;241;43m30\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnum\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 3\u001b[0m \u001b[38;5;28mprint\u001b[39m(greater)\n", 229 | "\u001b[1;31mTypeError\u001b[0m: 'list' object is not callable" 230 | ] 231 | } 232 | ], 233 | "source": [ 234 | "num = [19, 34, 45, 23, 12, 33]\n", 235 | "greater = list(filter(lambda num: num>30, num))\n", 236 | "print(greater)" 237 | ] 238 | }, 239 | { 240 | "cell_type": "code", 241 | "execution_count": 39, 242 | "id": "554da57e", 243 | "metadata": { 244 | "scrolled": false 245 | }, 246 | "outputs": [ 247 | { 248 | "ename": "TypeError", 249 | "evalue": "'list' object is not callable", 250 | "output_type": "error", 251 | "traceback": [ 252 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 253 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 254 | "Cell \u001b[1;32mIn[39], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m## Map function along with the lambda function\u001b[39;00m\n\u001b[0;32m 2\u001b[0m list1 \u001b[38;5;241m=\u001b[39m [\u001b[38;5;241m2\u001b[39m,\u001b[38;5;241m5\u001b[39m,\u001b[38;5;241m10\u001b[39m,\u001b[38;5;241m6\u001b[39m,\u001b[38;5;241m4\u001b[39m,\u001b[38;5;241m12\u001b[39m]\n\u001b[1;32m----> 3\u001b[0m double_the_num \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mlist\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mmap\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43;01mlambda\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mx\u001b[49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mx\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m2\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mlist1\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 4\u001b[0m \u001b[38;5;28mprint\u001b[39m(double_the_num)\n", 255 | "\u001b[1;31mTypeError\u001b[0m: 'list' object is not callable" 256 | ] 257 | } 258 | ], 259 | "source": [ 260 | "## Map function along with the lambda function\n", 261 | "list1 = [2,5,10,6,4,12]\n", 262 | "double_the_num = list(map(lambda x: x*2, list1))\n", 263 | "print(double_the_num)" 264 | ] 265 | }, 266 | { 267 | "cell_type": "markdown", 268 | "id": "602125e2", 269 | "metadata": {}, 270 | "source": [] 271 | }, 272 | { 273 | "cell_type": "code", 274 | "execution_count": 40, 275 | "id": "a5d81834", 276 | "metadata": {}, 277 | "outputs": [ 278 | { 279 | "ename": "TypeError", 280 | "evalue": "'list' object is not callable", 281 | "output_type": "error", 282 | "traceback": [ 283 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 284 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 285 | "Cell \u001b[1;32mIn[40], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m list3 \u001b[38;5;241m=\u001b[39m [\u001b[38;5;241m2\u001b[39m,\u001b[38;5;241m5\u001b[39m,\u001b[38;5;241m10\u001b[39m,\u001b[38;5;241m6\u001b[39m,\u001b[38;5;241m4\u001b[39m,\u001b[38;5;241m12\u001b[39m]\n\u001b[0;32m 2\u001b[0m cube \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mmap\u001b[39m(\u001b[38;5;28;01mlambda\u001b[39;00m x: \u001b[38;5;28mpow\u001b[39m(x,\u001b[38;5;241m3\u001b[39m), list3)\n\u001b[1;32m----> 3\u001b[0m \u001b[38;5;28;43mlist\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mcube\u001b[49m\u001b[43m)\u001b[49m\n", 286 | "\u001b[1;31mTypeError\u001b[0m: 'list' object is not callable" 287 | ] 288 | } 289 | ], 290 | "source": [ 291 | "list3 = [2,5,10,6,4,12]\n", 292 | "cube = map(lambda x: pow(x,3), list3)\n", 293 | "list(cube)" 294 | ] 295 | }, 296 | { 297 | "cell_type": "code", 298 | "execution_count": 41, 299 | "id": "165a75e0", 300 | "metadata": {}, 301 | "outputs": [ 302 | { 303 | "name": "stdout", 304 | "output_type": "stream", 305 | "text": [ 306 | "39\n" 307 | ] 308 | } 309 | ], 310 | "source": [ 311 | "from functools import reduce\n", 312 | "list4 = [2,5,10,6,4,12]\n", 313 | "sum = reduce((lambda x,y: x+y), list4)\n", 314 | "print(sum)" 315 | ] 316 | }, 317 | { 318 | "cell_type": "code", 319 | "execution_count": 42, 320 | "id": "ac3ede52", 321 | "metadata": {}, 322 | "outputs": [ 323 | { 324 | "name": "stdout", 325 | "output_type": "stream", 326 | "text": [ 327 | "28800\n" 328 | ] 329 | } 330 | ], 331 | "source": [ 332 | "from functools import reduce\n", 333 | "list4 = [2,5,10,6,4,12]\n", 334 | "pro = reduce((lambda x,y: x*y), list4)\n", 335 | "print(pro)" 336 | ] 337 | }, 338 | { 339 | "cell_type": "code", 340 | "execution_count": 45, 341 | "id": "f5e2b03c", 342 | "metadata": {}, 343 | "outputs": [ 344 | { 345 | "data": { 346 | "text/plain": [ 347 | "19" 348 | ] 349 | }, 350 | "execution_count": 45, 351 | "metadata": {}, 352 | "output_type": "execute_result" 353 | } 354 | ], 355 | "source": [ 356 | "def quadratic(a,b,c):\n", 357 | " return lambda x: a*x*2 + b*x +c \n", 358 | "f = quadratic(2,3,5)\n", 359 | "f(2) ## value of x" 360 | ] 361 | }, 362 | { 363 | "cell_type": "code", 364 | "execution_count": null, 365 | "id": "2fd8cd39", 366 | "metadata": {}, 367 | "outputs": [], 368 | "source": [] 369 | } 370 | ], 371 | "metadata": { 372 | "kernelspec": { 373 | "display_name": "Python 3 (ipykernel)", 374 | "language": "python", 375 | "name": "python3" 376 | }, 377 | "language_info": { 378 | "codemirror_mode": { 379 | "name": "ipython", 380 | "version": 3 381 | }, 382 | "file_extension": ".py", 383 | "mimetype": "text/x-python", 384 | "name": "python", 385 | "nbconvert_exporter": "python", 386 | "pygments_lexer": "ipython3", 387 | "version": "3.10.9" 388 | } 389 | }, 390 | "nbformat": 4, 391 | "nbformat_minor": 5 392 | } 393 | -------------------------------------------------------------------------------- /notebooks/Loops and iterators.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "c4b7cedf", 6 | "metadata": {}, 7 | "source": [ 8 | "# Iterations and loops\n", 9 | "for i in range(start,stop,step)" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": 4, 15 | "id": "db237e68", 16 | "metadata": {}, 17 | "outputs": [ 18 | { 19 | "name": "stdout", 20 | "output_type": "stream", 21 | "text": [ 22 | "0_1_2_3_4_5_6_7_8_9_" 23 | ] 24 | } 25 | ], 26 | "source": [ 27 | "for i in range(0,10):\n", 28 | " print(i,end='_')" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 13, 34 | "id": "a5f0dddf", 35 | "metadata": {}, 36 | "outputs": [ 37 | { 38 | "name": "stdout", 39 | "output_type": "stream", 40 | "text": [ 41 | "10_8_6_4_" 42 | ] 43 | } 44 | ], 45 | "source": [ 46 | "for i in range(10,2,-2):\n", 47 | " print(i,end='_')" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": 14, 53 | "id": "be373b64", 54 | "metadata": {}, 55 | "outputs": [ 56 | { 57 | "name": "stdout", 58 | "output_type": "stream", 59 | "text": [ 60 | "10\n", 61 | "8\n", 62 | "6\n", 63 | "4\n" 64 | ] 65 | } 66 | ], 67 | "source": [ 68 | "for i in range(10,2,-2):\n", 69 | " print(i)" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 26, 75 | "id": "9b7c175c", 76 | "metadata": {}, 77 | "outputs": [ 78 | { 79 | "name": "stdout", 80 | "output_type": "stream", 81 | "text": [ 82 | "****\n", 83 | "****\n", 84 | "****\n" 85 | ] 86 | } 87 | ], 88 | "source": [ 89 | "for i in range(0,3):\n", 90 | " for j in range(0,4):\n", 91 | " print(\"*\",end='')\n", 92 | " print('') " 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 43, 98 | "id": "b71a1af5", 99 | "metadata": {}, 100 | "outputs": [ 101 | { 102 | "name": "stdout", 103 | "output_type": "stream", 104 | "text": [ 105 | "0\n", 106 | "01\n", 107 | "012\n", 108 | "0123\n" 109 | ] 110 | } 111 | ], 112 | "source": [ 113 | " for i in range(0,4):\n", 114 | " for j in range(0,i+1):\n", 115 | " print(j,end=\"\")\n", 116 | " print(\"\")" 117 | ] 118 | }, 119 | { 120 | "cell_type": "code", 121 | "execution_count": 35, 122 | "id": "c6a6454a", 123 | "metadata": {}, 124 | "outputs": [ 125 | { 126 | "name": "stdout", 127 | "output_type": "stream", 128 | "text": [ 129 | "*\n", 130 | "**\n", 131 | "***\n", 132 | "****\n" 133 | ] 134 | } 135 | ], 136 | "source": [ 137 | "for i in range(0,4):\n", 138 | " for j in range(0,i+1):\n", 139 | " print(\"*\",end=\"\")\n", 140 | " print(\"\")" 141 | ] 142 | }, 143 | { 144 | "cell_type": "code", 145 | "execution_count": 42, 146 | "id": "17c85c03", 147 | "metadata": {}, 148 | "outputs": [ 149 | { 150 | "name": "stdout", 151 | "output_type": "stream", 152 | "text": [ 153 | "*****\n", 154 | "****\n", 155 | "***\n", 156 | "**\n", 157 | "*\n" 158 | ] 159 | } 160 | ], 161 | "source": [ 162 | "for i in range(0,5):\n", 163 | " for j in range(i-1,4):\n", 164 | " print(\"*\",end=\"\")\n", 165 | " print(\"\")" 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": 6, 171 | "id": "101204f7", 172 | "metadata": {}, 173 | "outputs": [ 174 | { 175 | "ename": "SyntaxError", 176 | "evalue": "invalid syntax (3948198345.py, line 2)", 177 | "output_type": "error", 178 | "traceback": [ 179 | "\u001b[1;36m Cell \u001b[1;32mIn[6], line 2\u001b[1;36m\u001b[0m\n\u001b[1;33m for i in the range(0,3)\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" 180 | ] 181 | } 182 | ], 183 | "source": [ 184 | "list1= ['A','B','c','D']\n", 185 | "for i in the range(0,3)\n", 186 | " print('list1[i]')" 187 | ] 188 | }, 189 | { 190 | "cell_type": "code", 191 | "execution_count": 1, 192 | "id": "9054b981", 193 | "metadata": {}, 194 | "outputs": [ 195 | { 196 | "ename": "SyntaxError", 197 | "evalue": "invalid syntax (3669401308.py, line 1)", 198 | "output_type": "error", 199 | "traceback": [ 200 | "\u001b[1;36m Cell \u001b[1;32mIn[1], line 1\u001b[1;36m\u001b[0m\n\u001b[1;33m for i in the range(0,3)\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" 201 | ] 202 | } 203 | ], 204 | "source": [ 205 | "for i in the range(0,3)\n", 206 | " for j in the range(i-1,3)\n", 207 | " print(\"\")" 208 | ] 209 | }, 210 | { 211 | "cell_type": "code", 212 | "execution_count": 4, 213 | "id": "0275d946", 214 | "metadata": {}, 215 | "outputs": [ 216 | { 217 | "name": "stdout", 218 | "output_type": "stream", 219 | "text": [ 220 | "1\n", 221 | "2\n", 222 | "3\n", 223 | "Found!!\n" 224 | ] 225 | } 226 | ], 227 | "source": [ 228 | "nums = [1,2,3,4,5]\n", 229 | "\n", 230 | "for num in nums:\n", 231 | " if num ==4:\n", 232 | " print('Found!!')\n", 233 | " break\n", 234 | " print(num) " 235 | ] 236 | }, 237 | { 238 | "cell_type": "code", 239 | "execution_count": 5, 240 | "id": "645faeb4", 241 | "metadata": {}, 242 | "outputs": [ 243 | { 244 | "name": "stdout", 245 | "output_type": "stream", 246 | "text": [ 247 | "1\n", 248 | "2\n", 249 | "3\n", 250 | "Found!!\n", 251 | "5\n" 252 | ] 253 | } 254 | ], 255 | "source": [ 256 | "nums = [1,2,3,4,5]\n", 257 | "\n", 258 | "for num in nums:\n", 259 | " if num ==4:\n", 260 | " print('Found!!')\n", 261 | " continue\n", 262 | " print(num) " 263 | ] 264 | }, 265 | { 266 | "cell_type": "code", 267 | "execution_count": 9, 268 | "id": "18244c16", 269 | "metadata": {}, 270 | "outputs": [ 271 | { 272 | "name": "stdout", 273 | "output_type": "stream", 274 | "text": [ 275 | "1 a\n", 276 | "1 b\n", 277 | "1 c\n", 278 | "2 a\n", 279 | "2 b\n", 280 | "2 c\n", 281 | "3 a\n", 282 | "3 b\n", 283 | "3 c\n", 284 | "4 a\n", 285 | "4 b\n", 286 | "4 c\n", 287 | "5 a\n", 288 | "5 b\n", 289 | "5 c\n" 290 | ] 291 | } 292 | ], 293 | "source": [ 294 | "nums = [1,2,3,4,5]\n", 295 | "\n", 296 | "for num in nums:\n", 297 | " for letter in 'abc':\n", 298 | " print(num,letter) " 299 | ] 300 | }, 301 | { 302 | "cell_type": "code", 303 | "execution_count": 14, 304 | "id": "d3de9752", 305 | "metadata": {}, 306 | "outputs": [ 307 | { 308 | "name": "stdout", 309 | "output_type": "stream", 310 | "text": [ 311 | "1 abc\n", 312 | "1 b\n", 313 | "1 c\n", 314 | "2 abc\n", 315 | "2 b\n", 316 | "2 c\n", 317 | "3 abc\n", 318 | "3 b\n", 319 | "3 c\n", 320 | "4 abc\n", 321 | "4 b\n", 322 | "4 c\n", 323 | "5 abc\n", 324 | "5 b\n", 325 | "5 c\n" 326 | ] 327 | } 328 | ], 329 | "source": [ 330 | "nums = [1,2,3,4,5]\n", 331 | "alpha =['abc','b','c']\n", 332 | "for num in nums:\n", 333 | " for letter in alpha:\n", 334 | " print(num,letter) " 335 | ] 336 | }, 337 | { 338 | "cell_type": "code", 339 | "execution_count": 16, 340 | "id": "75bddde3", 341 | "metadata": {}, 342 | "outputs": [ 343 | { 344 | "name": "stdout", 345 | "output_type": "stream", 346 | "text": [ 347 | "1 a\n", 348 | "1 b\n", 349 | "1 c\n", 350 | "2 a\n", 351 | "2 b\n", 352 | "2 c\n", 353 | "3 a\n", 354 | "3 b\n", 355 | "3 c\n", 356 | "4 a\n", 357 | "4 b\n", 358 | "4 c\n", 359 | "5 a\n", 360 | "5 b\n", 361 | "5 c\n" 362 | ] 363 | } 364 | ], 365 | "source": [ 366 | "nums = [1,2,3,4,5]\n", 367 | "alpha = 'abc'\n", 368 | "for num in nums:\n", 369 | " for letter in alpha:\n", 370 | " print(num,letter) " 371 | ] 372 | }, 373 | { 374 | "cell_type": "code", 375 | "execution_count": 22, 376 | "id": "0a8eda27", 377 | "metadata": {}, 378 | "outputs": [ 379 | { 380 | "name": "stdout", 381 | "output_type": "stream", 382 | "text": [ 383 | "1\n", 384 | "2\n", 385 | "3\n", 386 | "4\n", 387 | "5\n", 388 | "6\n", 389 | "7\n", 390 | "8\n", 391 | "9\n" 392 | ] 393 | } 394 | ], 395 | "source": [ 396 | "nums = 1\n", 397 | "while nums < 10:\n", 398 | " print(nums)\n", 399 | " nums += 1" 400 | ] 401 | }, 402 | { 403 | "cell_type": "code", 404 | "execution_count": null, 405 | "id": "960c37a9", 406 | "metadata": {}, 407 | "outputs": [], 408 | "source": [ 409 | "nums = 1\n", 410 | "while True:\n", 411 | "if nums ==5:\n", 412 | " break\n", 413 | "print(nums)\n", 414 | "nums += 1" 415 | ] 416 | }, 417 | { 418 | "cell_type": "code", 419 | "execution_count": null, 420 | "id": "882a24cb", 421 | "metadata": {}, 422 | "outputs": [], 423 | "source": [] 424 | } 425 | ], 426 | "metadata": { 427 | "kernelspec": { 428 | "display_name": "Python 3 (ipykernel)", 429 | "language": "python", 430 | "name": "python3" 431 | }, 432 | "language_info": { 433 | "codemirror_mode": { 434 | "name": "ipython", 435 | "version": 3 436 | }, 437 | "file_extension": ".py", 438 | "mimetype": "text/x-python", 439 | "name": "python", 440 | "nbconvert_exporter": "python", 441 | "pygments_lexer": "ipython3", 442 | "version": "3.10.9" 443 | } 444 | }, 445 | "nbformat": 4, 446 | "nbformat_minor": 5 447 | } 448 | -------------------------------------------------------------------------------- /notebooks/Python basics.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "id": "66bb72ca", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "#dictionaries \n", 11 | "a ={1:\"first name\",2:\"second name\",3:\"third name\"}\n" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": null, 17 | "id": "ea6912db", 18 | "metadata": {}, 19 | "outputs": [], 20 | "source": [] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": 1, 25 | "id": "33f6bc5d", 26 | "metadata": {}, 27 | "outputs": [ 28 | { 29 | "name": "stdout", 30 | "output_type": "stream", 31 | "text": [ 32 | "5\n" 33 | ] 34 | } 35 | ], 36 | "source": [ 37 | "a=10//2\n", 38 | "print(a)" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": null, 44 | "id": "5e38f3d8", 45 | "metadata": {}, 46 | "outputs": [], 47 | "source": [ 48 | "\n", 49 | "print(\"My first name\")" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": 2, 55 | "id": "05ea10fc", 56 | "metadata": {}, 57 | "outputs": [ 58 | { 59 | "name": "stdout", 60 | "output_type": "stream", 61 | "text": [ 62 | "5.0\n" 63 | ] 64 | } 65 | ], 66 | "source": [ 67 | "a=10/2\n", 68 | "print(a)" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": 3, 74 | "id": "6c016c4e", 75 | "metadata": {}, 76 | "outputs": [ 77 | { 78 | "name": "stdout", 79 | "output_type": "stream", 80 | "text": [ 81 | "[1, 2, 'string']\n" 82 | ] 83 | } 84 | ], 85 | "source": [ 86 | "list1= [1,2,\"string\"]\n", 87 | "print(list1)" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": 4, 93 | "id": "3382e434", 94 | "metadata": {}, 95 | "outputs": [ 96 | { 97 | "name": "stdout", 98 | "output_type": "stream", 99 | "text": [ 100 | "0\n", 101 | "1\n", 102 | "2\n", 103 | "3\n", 104 | "4\n", 105 | "5\n", 106 | "6\n", 107 | "7\n", 108 | "8\n", 109 | "9\n", 110 | "10\n" 111 | ] 112 | } 113 | ], 114 | "source": [ 115 | "for i in range(0,11):\n", 116 | " print(i)" 117 | ] 118 | }, 119 | { 120 | "cell_type": "code", 121 | "execution_count": 7, 122 | "id": "670ebc0b", 123 | "metadata": {}, 124 | "outputs": [ 125 | { 126 | "name": "stdout", 127 | "output_type": "stream", 128 | "text": [ 129 | "11\n", 130 | "10\n", 131 | "9\n", 132 | "8\n", 133 | "7\n", 134 | "6\n", 135 | "5\n", 136 | "4\n", 137 | "3\n", 138 | "2\n", 139 | "1\n" 140 | ] 141 | } 142 | ], 143 | "source": [ 144 | "for i in range(11,0,-1):\n", 145 | " print(i)" 146 | ] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "execution_count": 2, 151 | "id": "a84aa53e", 152 | "metadata": {}, 153 | "outputs": [ 154 | { 155 | "name": "stdout", 156 | "output_type": "stream", 157 | "text": [ 158 | "john\n" 159 | ] 160 | } 161 | ], 162 | "source": [ 163 | "#dictionaries\n", 164 | "student= {'name': 'john','age':22,'courses':['Math','Compsci']}\n", 165 | "print(student['name'])" 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": 1, 171 | "id": "635833e7", 172 | "metadata": {}, 173 | "outputs": [ 174 | { 175 | "name": "stdout", 176 | "output_type": "stream", 177 | "text": [ 178 | "john\n" 179 | ] 180 | } 181 | ], 182 | "source": [ 183 | "#dictionaries\n", 184 | "student= {'name': 'john','age':22,'courses':['Math','Compsci']}\n", 185 | "print(student['name'])" 186 | ] 187 | }, 188 | { 189 | "cell_type": "code", 190 | "execution_count": 2, 191 | "id": "bbb6bd54", 192 | "metadata": {}, 193 | "outputs": [ 194 | { 195 | "ename": "SyntaxError", 196 | "evalue": "invalid syntax (2023507962.py, line 1)", 197 | "output_type": "error", 198 | "traceback": [ 199 | "\u001b[1;36m Cell \u001b[1;32mIn[2], line 1\u001b[1;36m\u001b[0m\n\u001b[1;33m Python opertator\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" 200 | ] 201 | } 202 | ], 203 | "source": [ 204 | "Python opertator \n", 205 | "1. Equality operator\n", 206 | " is,is not, ==,!=\n", 207 | "2. Comparsion operator\n", 208 | "<,>,<=,>=\n", 209 | "3. Arithmetic operator\n", 210 | "+,-,/(float),//,*\n", 211 | "4. Logical operator\n", 212 | " Not,and,or" 213 | ] 214 | }, 215 | { 216 | "cell_type": "code", 217 | "execution_count": 4, 218 | "id": "ae9b6101", 219 | "metadata": {}, 220 | "outputs": [ 221 | { 222 | "data": { 223 | "text/plain": [ 224 | "True" 225 | ] 226 | }, 227 | "execution_count": 4, 228 | "metadata": {}, 229 | "output_type": "execute_result" 230 | } 231 | ], 232 | "source": [ 233 | "a=True\n", 234 | "b=False\n", 235 | "a or b\n" 236 | ] 237 | }, 238 | { 239 | "cell_type": "code", 240 | "execution_count": 5, 241 | "id": "d45bf7d0", 242 | "metadata": { 243 | "scrolled": true 244 | }, 245 | "outputs": [ 246 | { 247 | "data": { 248 | "text/plain": [ 249 | "False" 250 | ] 251 | }, 252 | "execution_count": 5, 253 | "metadata": {}, 254 | "output_type": "execute_result" 255 | } 256 | ], 257 | "source": [ 258 | "a=True\n", 259 | "b=False\n", 260 | "a & b" 261 | ] 262 | }, 263 | { 264 | "cell_type": "code", 265 | "execution_count": 6, 266 | "id": "09390326", 267 | "metadata": {}, 268 | "outputs": [ 269 | { 270 | "data": { 271 | "text/plain": [ 272 | "True" 273 | ] 274 | }, 275 | "execution_count": 6, 276 | "metadata": {}, 277 | "output_type": "execute_result" 278 | } 279 | ], 280 | "source": [ 281 | "a=True\n", 282 | "b=False\n", 283 | "a !=b" 284 | ] 285 | }, 286 | { 287 | "cell_type": "code", 288 | "execution_count": null, 289 | "id": "97100f96", 290 | "metadata": {}, 291 | "outputs": [], 292 | "source": [ 293 | "age =int(input(\"Enter the age\"))\n", 294 | "if (age<18 or age>=35):\n", 295 | " print(\"Your memory is not that fast\")\n", 296 | "else: print(\"Your memory is not that fast\")" 297 | ] 298 | }, 299 | { 300 | "cell_type": "code", 301 | "execution_count": 11, 302 | "id": "dc896a25", 303 | "metadata": {}, 304 | "outputs": [ 305 | { 306 | "data": { 307 | "text/plain": [ 308 | "False" 309 | ] 310 | }, 311 | "execution_count": 11, 312 | "metadata": {}, 313 | "output_type": "execute_result" 314 | } 315 | ], 316 | "source": [ 317 | "a=\"Marvel\"\n", 318 | "b=\"Disney\"\n", 319 | "a==b" 320 | ] 321 | }, 322 | { 323 | "cell_type": "code", 324 | "execution_count": 15, 325 | "id": "6bab4e3c", 326 | "metadata": {}, 327 | "outputs": [ 328 | { 329 | "name": "stdout", 330 | "output_type": "stream", 331 | "text": [ 332 | "Enter the age 18\n", 333 | "You are in the teenage\n" 334 | ] 335 | } 336 | ], 337 | "source": [ 338 | "age=int(input(\"Enter the age \"))\n", 339 | "if age==18:\n", 340 | " print(\"You are in the teenage\")" 341 | ] 342 | }, 343 | { 344 | "cell_type": "code", 345 | "execution_count": 12, 346 | "id": "240b6ef5", 347 | "metadata": {}, 348 | "outputs": [ 349 | { 350 | "name": "stdout", 351 | "output_type": "stream", 352 | "text": [ 353 | "1570455268080\n", 354 | "1570455270192\n" 355 | ] 356 | } 357 | ], 358 | "source": [ 359 | "a=\"Marvel\"\n", 360 | "b=\"Disney\"\n", 361 | "print(id(a))\n", 362 | "print(id(b))" 363 | ] 364 | }, 365 | { 366 | "cell_type": "code", 367 | "execution_count": 13, 368 | "id": "f2a6d7b9", 369 | "metadata": {}, 370 | "outputs": [ 371 | { 372 | "data": { 373 | "text/plain": [ 374 | "False" 375 | ] 376 | }, 377 | "execution_count": 13, 378 | "metadata": {}, 379 | "output_type": "execute_result" 380 | } 381 | ], 382 | "source": [ 383 | "a is b" 384 | ] 385 | }, 386 | { 387 | "cell_type": "markdown", 388 | "id": "0e88efbb", 389 | "metadata": {}, 390 | "source": [ 391 | "Python control flow\n", 392 | "if/else statements\n" 393 | ] 394 | }, 395 | { 396 | "cell_type": "code", 397 | "execution_count": 27, 398 | "id": "de991388", 399 | "metadata": {}, 400 | "outputs": [ 401 | { 402 | "name": "stdout", 403 | "output_type": "stream", 404 | "text": [ 405 | "Enter the age 3\n", 406 | "Enter the age 3\n", 407 | "Values are equal\n" 408 | ] 409 | } 410 | ], 411 | "source": [ 412 | "age_1=int(input(\"Enter the age \"))\n", 413 | "age_2=int(input(\"Enter the age \"))\n", 414 | "if(age_1>age_2):\n", 415 | " print(age_1)\n", 416 | "elif(age_1==age_2):\n", 417 | " print(\"Values are equal\")\n", 418 | "else:\n", 419 | " print(age_2)" 420 | ] 421 | }, 422 | { 423 | "cell_type": "code", 424 | "execution_count": 23, 425 | "id": "831ad687", 426 | "metadata": {}, 427 | "outputs": [ 428 | { 429 | "name": "stdout", 430 | "output_type": "stream", 431 | "text": [ 432 | "Enter the number5\n", 433 | "\n", 434 | "The number is odd\n" 435 | ] 436 | } 437 | ], 438 | "source": [ 439 | "val=input(\"Enter the number\")\n", 440 | "value_float=float(val)\n", 441 | "print(type(value_float))\n", 442 | "if(value_float%2==0):\n", 443 | " print(\"The number is even\")\n", 444 | "else:\n", 445 | " print(\"The number is odd\")" 446 | ] 447 | }, 448 | { 449 | "cell_type": "code", 450 | "execution_count": 24, 451 | "id": "4bfb0c88", 452 | "metadata": {}, 453 | "outputs": [ 454 | { 455 | "data": { 456 | "text/plain": [ 457 | "False" 458 | ] 459 | }, 460 | "execution_count": 24, 461 | "metadata": {}, 462 | "output_type": "execute_result" 463 | } 464 | ], 465 | "source": [ 466 | "10%2!=0\n" 467 | ] 468 | }, 469 | { 470 | "cell_type": "code", 471 | "execution_count": null, 472 | "id": "225526ea", 473 | "metadata": {}, 474 | "outputs": [], 475 | "source": [] 476 | }, 477 | { 478 | "cell_type": "code", 479 | "execution_count": null, 480 | "id": "7087101b", 481 | "metadata": {}, 482 | "outputs": [], 483 | "source": [ 484 | "val=input(\"Enter the age\")\n", 485 | "value_float=float(val)\n", 486 | "print(type(value_float))\n", 487 | "if(val<20):\n", 488 | " print(\"Teen\")\n", 489 | "elif(2040):\n", 492 | " print(\"senior\")" 493 | ] 494 | }, 495 | { 496 | "cell_type": "code", 497 | "execution_count": 3, 498 | "id": "68e6a41b", 499 | "metadata": {}, 500 | "outputs": [ 501 | { 502 | "name": "stdout", 503 | "output_type": "stream", 504 | "text": [ 505 | "Enter the age23\n", 506 | "\n" 507 | ] 508 | }, 509 | { 510 | "ename": "TypeError", 511 | "evalue": "'<' not supported between instances of 'str' and 'int'", 512 | "output_type": "error", 513 | "traceback": [ 514 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 515 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 516 | "Cell \u001b[1;32mIn[3], line 4\u001b[0m\n\u001b[0;32m 2\u001b[0m value_float\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mfloat\u001b[39m(val)\n\u001b[0;32m 3\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28mtype\u001b[39m(value_float))\n\u001b[1;32m----> 4\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m(\u001b[43mval\u001b[49m\u001b[38;5;241;43m<\u001b[39;49m\u001b[38;5;241;43m20\u001b[39;49m):\n\u001b[0;32m 5\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mTeen\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m 6\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m(\u001b[38;5;241m20\u001b[39m\u001b[38;5;241m<\u001b[39mval\u001b[38;5;241m<\u001b[39m\u001b[38;5;241m40\u001b[39m):\n", 517 | "\u001b[1;31mTypeError\u001b[0m: '<' not supported between instances of 'str' and 'int'" 518 | ] 519 | } 520 | ], 521 | "source": [ 522 | "val=input(\"Enter the age\")\n", 523 | "value_float=float(val)\n", 524 | "print(type(value_float))\n", 525 | "if(val<20):\n", 526 | " print(\"Teen\")\n", 527 | "elif(20\"Open" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": 1, 32 | "metadata": { 33 | "colab": { 34 | "base_uri": "https://localhost:8080/" 35 | }, 36 | "id": "7oGcdJ7SPFBL", 37 | "outputId": "9f86dd90-ea4d-449d-ab06-f951ab4de6e3" 38 | }, 39 | "outputs": [ 40 | { 41 | "output_type": "stream", 42 | "name": "stdout", 43 | "text": [ 44 | "7\n" 45 | ] 46 | } 47 | ], 48 | "source": [ 49 | "l = [True, 1, 2,3,False]\n", 50 | "print(sum(l))" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "source": [ 56 | "l1 = [3,4,5,6]\n", 57 | "l1.append(8)\n", 58 | "print(l1)" 59 | ], 60 | "metadata": { 61 | "colab": { 62 | "base_uri": "https://localhost:8080/" 63 | }, 64 | "id": "Yv4vf_MIWDlm", 65 | "outputId": "31cd080a-5d6c-465c-e6ae-9422ebc6de0c" 66 | }, 67 | "execution_count": 8, 68 | "outputs": [ 69 | { 70 | "output_type": "stream", 71 | "name": "stdout", 72 | "text": [ 73 | "[3, 4, 5, 6, 8]\n" 74 | ] 75 | } 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "source": [ 81 | "l2 = [8,5,2,9]\n", 82 | "l2.sort()\n", 83 | "print(l2)" 84 | ], 85 | "metadata": { 86 | "colab": { 87 | "base_uri": "https://localhost:8080/" 88 | }, 89 | "id": "OgoPNRLQWqLL", 90 | "outputId": "e3556ffe-1cf8-40b6-cf42-e3ad15240e5b" 91 | }, 92 | "execution_count": 4, 93 | "outputs": [ 94 | { 95 | "output_type": "stream", 96 | "name": "stdout", 97 | "text": [ 98 | "[2, 5, 8, 9]\n" 99 | ] 100 | } 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "source": [ 106 | "l1 = [3,4,5,6]\n", 107 | "l1.insert(2,8)\n", 108 | "print(l1)" 109 | ], 110 | "metadata": { 111 | "colab": { 112 | "base_uri": "https://localhost:8080/" 113 | }, 114 | "id": "9aVGJp2BXCKz", 115 | "outputId": "5be1bff5-91c9-4dc1-95bb-a30b9cbbb3f3" 116 | }, 117 | "execution_count": 9, 118 | "outputs": [ 119 | { 120 | "output_type": "stream", 121 | "name": "stdout", 122 | "text": [ 123 | "[3, 4, 8, 5, 6]\n" 124 | ] 125 | } 126 | ] 127 | }, 128 | { 129 | "cell_type": "code", 130 | "source": [ 131 | "l1 = [3,4,5,6]\n", 132 | "l2 = [8,5,2,9]\n", 133 | "l1.extend(l2)\n", 134 | "print(l1)" 135 | ], 136 | "metadata": { 137 | "colab": { 138 | "base_uri": "https://localhost:8080/" 139 | }, 140 | "id": "kDM65tZqXsLc", 141 | "outputId": "c9f9b440-1aaf-43cd-a36e-f8ae2bb1e9b8" 142 | }, 143 | "execution_count": 12, 144 | "outputs": [ 145 | { 146 | "output_type": "stream", 147 | "name": "stdout", 148 | "text": [ 149 | "[3, 4, 5, 6, 8, 5, 2, 9]\n" 150 | ] 151 | } 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "source": [ 157 | "l1 = [3,4,5,6]\n", 158 | "l2 = [8,5,2,9]\n", 159 | "l1.append(l2)\n", 160 | "print(l1)" 161 | ], 162 | "metadata": { 163 | "colab": { 164 | "base_uri": "https://localhost:8080/" 165 | }, 166 | "id": "9YxyDMEpX5tj", 167 | "outputId": "91c61c4b-2786-4214-8c9b-a7beff8da00f" 168 | }, 169 | "execution_count": 13, 170 | "outputs": [ 171 | { 172 | "output_type": "stream", 173 | "name": "stdout", 174 | "text": [ 175 | "[3, 4, 5, 6, [8, 5, 2, 9]]\n" 176 | ] 177 | } 178 | ] 179 | }, 180 | { 181 | "cell_type": "code", 182 | "source": [ 183 | "l2 = [8,5,2,9]\n", 184 | "l2.sort(reverse = True)\n", 185 | "print(l2)" 186 | ], 187 | "metadata": { 188 | "colab": { 189 | "base_uri": "https://localhost:8080/" 190 | }, 191 | "id": "k9Xu-CSSYN-B", 192 | "outputId": "dc7b6009-c6a4-48be-deb6-bc4c23ed0707" 193 | }, 194 | "execution_count": 14, 195 | "outputs": [ 196 | { 197 | "output_type": "stream", 198 | "name": "stdout", 199 | "text": [ 200 | "[9, 8, 5, 2]\n" 201 | ] 202 | } 203 | ] 204 | }, 205 | { 206 | "cell_type": "code", 207 | "source": [ 208 | "l4 = sorted('python')\n", 209 | "print(l4)" 210 | ], 211 | "metadata": { 212 | "colab": { 213 | "base_uri": "https://localhost:8080/" 214 | }, 215 | "id": "AQQ6LsxVYXEO", 216 | "outputId": "ea52af80-d6c3-45c8-facb-40d7c215b058" 217 | }, 218 | "execution_count": 15, 219 | "outputs": [ 220 | { 221 | "output_type": "stream", 222 | "name": "stdout", 223 | "text": [ 224 | "['h', 'n', 'o', 'p', 't', 'y']\n" 225 | ] 226 | } 227 | ] 228 | }, 229 | { 230 | "cell_type": "code", 231 | "source": [ 232 | "l4 = sorted('python',reverse = True)\n", 233 | "print(l4)" 234 | ], 235 | "metadata": { 236 | "colab": { 237 | "base_uri": "https://localhost:8080/" 238 | }, 239 | "id": "EQ5ybEuSYlFN", 240 | "outputId": "8e66ed9b-5d6d-459b-c2bc-af48dc580003" 241 | }, 242 | "execution_count": 19, 243 | "outputs": [ 244 | { 245 | "output_type": "stream", 246 | "name": "stdout", 247 | "text": [ 248 | "['y', 't', 'p', 'o', 'n', 'h']\n" 249 | ] 250 | } 251 | ] 252 | }, 253 | { 254 | "cell_type": "code", 255 | "source": [ 256 | "l2 = [8,5,2,9]\n", 257 | "print(l2.index(2))" 258 | ], 259 | "metadata": { 260 | "colab": { 261 | "base_uri": "https://localhost:8080/" 262 | }, 263 | "id": "jk9FW3oVYx8r", 264 | "outputId": "9a2bbe7f-23eb-4671-f77f-c693c9302a90" 265 | }, 266 | "execution_count": 21, 267 | "outputs": [ 268 | { 269 | "output_type": "stream", 270 | "name": "stdout", 271 | "text": [ 272 | "2\n" 273 | ] 274 | } 275 | ] 276 | }, 277 | { 278 | "cell_type": "code", 279 | "source": [ 280 | "l2 = [8,5,2,9,2,2,2]\n", 281 | "print(l2.count(2))" 282 | ], 283 | "metadata": { 284 | "colab": { 285 | "base_uri": "https://localhost:8080/" 286 | }, 287 | "id": "Tjw0Zk9aZlOd", 288 | "outputId": "ac0ee4de-aca1-4626-9291-8f5508512381" 289 | }, 290 | "execution_count": 22, 291 | "outputs": [ 292 | { 293 | "output_type": "stream", 294 | "name": "stdout", 295 | "text": [ 296 | "4\n" 297 | ] 298 | } 299 | ] 300 | }, 301 | { 302 | "cell_type": "code", 303 | "source": [ 304 | "l2 = [8,5,2,9]\n", 305 | "l2.remove(2)" 306 | ], 307 | "metadata": { 308 | "id": "HjjQv2y1Z1x9" 309 | }, 310 | "execution_count": 23, 311 | "outputs": [] 312 | }, 313 | { 314 | "cell_type": "code", 315 | "source": [ 316 | "print(l2)" 317 | ], 318 | "metadata": { 319 | "colab": { 320 | "base_uri": "https://localhost:8080/" 321 | }, 322 | "id": "OTc8jFfgacuS", 323 | "outputId": "fff1a7d9-51b2-4232-d276-9b3f777fc390" 324 | }, 325 | "execution_count": 24, 326 | "outputs": [ 327 | { 328 | "output_type": "stream", 329 | "name": "stdout", 330 | "text": [ 331 | "[8, 5, 9]\n" 332 | ] 333 | } 334 | ] 335 | }, 336 | { 337 | "cell_type": "code", 338 | "source": [ 339 | "l2 = [8,5,2,9]\n", 340 | "print(l2.pop())" 341 | ], 342 | "metadata": { 343 | "colab": { 344 | "base_uri": "https://localhost:8080/" 345 | }, 346 | "id": "i5ymJa30aeIE", 347 | "outputId": "9325620a-2050-4a94-ffee-087d0bdf5487" 348 | }, 349 | "execution_count": 25, 350 | "outputs": [ 351 | { 352 | "output_type": "stream", 353 | "name": "stdout", 354 | "text": [ 355 | "9\n" 356 | ] 357 | } 358 | ] 359 | }, 360 | { 361 | "cell_type": "code", 362 | "source": [ 363 | "l2 = [8,5,2,9,19,10]\n", 364 | "print(l2.pop(2))" 365 | ], 366 | "metadata": { 367 | "colab": { 368 | "base_uri": "https://localhost:8080/" 369 | }, 370 | "id": "t-La6xPNapLt", 371 | "outputId": "cff15a7d-5719-4231-dea6-8ee62e9264a1" 372 | }, 373 | "execution_count": 26, 374 | "outputs": [ 375 | { 376 | "output_type": "stream", 377 | "name": "stdout", 378 | "text": [ 379 | "2\n" 380 | ] 381 | } 382 | ] 383 | }, 384 | { 385 | "cell_type": "code", 386 | "source": [ 387 | "l2 = [8,5,2,9,19,10]\n", 388 | "print(l2.remove(9))" 389 | ], 390 | "metadata": { 391 | "colab": { 392 | "base_uri": "https://localhost:8080/" 393 | }, 394 | "id": "b8qUdsTMa-dr", 395 | "outputId": "e552f82f-795f-4365-bea9-1fe832eaa333" 396 | }, 397 | "execution_count": 30, 398 | "outputs": [ 399 | { 400 | "output_type": "stream", 401 | "name": "stdout", 402 | "text": [ 403 | "None\n" 404 | ] 405 | } 406 | ] 407 | }, 408 | { 409 | "cell_type": "code", 410 | "source": [ 411 | "l1 = [3,4,5,6]\n", 412 | "l2 = [8,5,2,9]\n", 413 | "\n", 414 | "print(cmp(l1,l2))" 415 | ], 416 | "metadata": { 417 | "colab": { 418 | "base_uri": "https://localhost:8080/", 419 | "height": 140 420 | }, 421 | "id": "-PaeI-6QbMvU", 422 | "outputId": "d39c502c-1c0d-4c7d-a681-96558391ac33" 423 | }, 424 | "execution_count": 33, 425 | "outputs": [ 426 | { 427 | "output_type": "error", 428 | "ename": "SyntaxError", 429 | "evalue": "ignored", 430 | "traceback": [ 431 | "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m4\u001b[0m\n\u001b[0;31m print cmp(l1,l2)\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m Missing parentheses in call to 'print'. Did you mean print(...)?\n" 432 | ] 433 | } 434 | ] 435 | }, 436 | { 437 | "cell_type": "code", 438 | "source": [], 439 | "metadata": { 440 | "id": "EX7oI24cb9SC" 441 | }, 442 | "execution_count": null, 443 | "outputs": [] 444 | } 445 | ] 446 | } -------------------------------------------------------------------------------- /resources/52 Python Question Answers.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utk2103/Python-for-beginners/e39e272a76d0efb70f860f0a23a9a6ae58a09c3b/resources/52 Python Question Answers.pdf -------------------------------------------------------------------------------- /resources/Automate the Boring Stuff with Python.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utk2103/Python-for-beginners/e39e272a76d0efb70f860f0a23a9a6ae58a09c3b/resources/Automate the Boring Stuff with Python.pdf -------------------------------------------------------------------------------- /resources/ListsOfInbuiltMethods.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utk2103/Python-for-beginners/e39e272a76d0efb70f860f0a23a9a6ae58a09c3b/resources/ListsOfInbuiltMethods.pdf -------------------------------------------------------------------------------- /resources/Python Notes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utk2103/Python-for-beginners/e39e272a76d0efb70f860f0a23a9a6ae58a09c3b/resources/Python Notes.pdf -------------------------------------------------------------------------------- /resources/python cheat sheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utk2103/Python-for-beginners/e39e272a76d0efb70f860f0a23a9a6ae58a09c3b/resources/python cheat sheet.pdf -------------------------------------------------------------------------------- /resources/python-crash-course.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utk2103/Python-for-beginners/e39e272a76d0efb70f860f0a23a9a6ae58a09c3b/resources/python-crash-course.pdf -------------------------------------------------------------------------------- /scripts/01.TwoSum.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def twoSum(self, nums, target): 3 | # Why: Pair value with index for tracking 4 | nums_index = [(v, index) for index, v in enumerate(nums)] 5 | nums_index.sort() # Why: Allows two-pointer search 6 | begin, end = 0, len(nums) - 1 7 | while begin < end: 8 | curr = nums_index[begin][0] + nums_index[end][0] 9 | if curr == target: 10 | return [nums_index[begin][1], nums_index[end][1]] # Why: Return original indices 11 | elif curr < target: 12 | begin += 1 # Why: Need a bigger sum 13 | else: 14 | end -= 1 # Why: Need a smaller sum 15 | -------------------------------------------------------------------------------- /scripts/BinarySearch.py: -------------------------------------------------------------------------------- 1 | def binarySearch(array, x, low, high): 2 | # Why: Efficiently search sorted array by dividing in half each time 3 | while low <= high: 4 | mid = low + (high - low)//2 # Why: Avoids overflow, finds middle 5 | if array[mid] == x: 6 | return mid # Why: Found target, return index 7 | elif array[mid] < x: 8 | low = mid + 1 # Why: Ignore left half 9 | else: 10 | high = mid - 1 # Why: Ignore right half 11 | return -1 # Why: Not found 12 | 13 | array = [3, 4, 5, 6, 7, 8, 9] # Why: Example sorted input 14 | x = 4 # Why: Target to search for 15 | result = binarySearch(array, x, 0, len(array)-1) 16 | 17 | if result != -1: 18 | print("Element is present at index " + str(result)) 19 | else: 20 | print("Not found") 21 | -------------------------------------------------------------------------------- /scripts/LinearSearch.py: -------------------------------------------------------------------------------- 1 | def linearSearch(array, n, x): 2 | # Why: Simple, works on any list (not just sorted) 3 | for i in range(0, n): 4 | if (array[i] == x): 5 | return i # Why: Return first match 6 | return -1 # Why: Not found 7 | 8 | array = [2, 4, 0, 1, 9] # Why: Example input 9 | x = 1 # Why: Target to search for 10 | n = len(array) 11 | result = linearSearch(array, n, x) 12 | if(result == -1): 13 | print("Element not found") 14 | else: 15 | print("Element found at index: ", result) 16 | -------------------------------------------------------------------------------- /scripts/MergeSort.py: -------------------------------------------------------------------------------- 1 | def mergeSort(array): 2 | # Why: Recursively splits and sorts, then merges 3 | if len(array) > 1: 4 | r = len(array)//2 5 | L = array[:r] # Why: Left half 6 | M = array[r:] # Why: Right half 7 | mergeSort(L) 8 | mergeSort(M) 9 | i = j = k = 0 10 | # Why: Merge sorted halves 11 | while i < len(L) and j < len(M): 12 | if L[i] < M[j]: 13 | array[k] = L[i] 14 | i += 1 15 | else: 16 | array[k] = M[j] 17 | j += 1 18 | k += 1 19 | while i < len(L): 20 | array[k] = L[i] 21 | i += 1 22 | k += 1 23 | while j < len(M): 24 | array[k] = M[j] 25 | j += 1 26 | k += 1 27 | 28 | def printList(array): 29 | for i in range(len(array)): 30 | print(array[i], end=" ") 31 | print() 32 | 33 | if __name__ == '__main__': 34 | array = [6, 5, 12, 10, 9, 1] # Why: Example unsorted list 35 | mergeSort(array) 36 | print("Sorted array is: ") 37 | printList(array) 38 | -------------------------------------------------------------------------------- /scripts/argparse_1.py: -------------------------------------------------------------------------------- 1 | import argparse # Why: Handles command-line args, avoids manual parsing 2 | 3 | if __name__ == "__main__": 4 | parser = argparse.ArgumentParser(description='Simple calculator for basic arithmetic operations.') # Why: Shows help/usage for users 5 | 6 | parser.add_argument("number1", help='First number', type=int) # Why: Forces user to provide an int 7 | parser.add_argument("number2", help='Second number', type=int) # Why: Ensures both numbers are present 8 | parser.add_argument("operation", help='Operation (add, subtract, multiply)', choices=["add", "subtract", "multiply"]) # Why: Prevents invalid operations 9 | 10 | args = parser.parse_args() # Why: Converts input to usable vars 11 | 12 | print(f'Number 1: {args.number1}') 13 | print(f'Number 2: {args.number2}') 14 | print(f'Operation: {args.operation}') 15 | 16 | n1 = args.number1 17 | n2 = args.number2 18 | result = None 19 | 20 | # Why: Simple branching, avoids eval/injection 21 | if args.operation == 'add': 22 | result = n1 + n2 23 | elif args.operation == 'subtract': 24 | result = n1 - n2 25 | elif args.operation == 'multiply': 26 | result = n1 * n2 27 | else: 28 | print(f'Invalid operation: {args.operation}') 29 | exit(1) 30 | 31 | print(f'Result: {result}') 32 | -------------------------------------------------------------------------------- /scripts/check.py: -------------------------------------------------------------------------------- 1 | # Why: Demo for function and input/output 2 | def func1(): 3 | # Why: Placeholder function for structure 4 | # utka 5 | # utkasfjh 6 | # jlfdjlj 7 | # jrlfjl 8 | print(func1) 9 | 10 | 11 | # Why: Show input/output in terminal 12 | # Make vs code compatible to take the input 13 | # make changes in code runner through settings -> run in terminal 14 | # -> Clear previous output 15 | # -> Save file before run 16 | print("Hello world") 17 | a = input("Enter a number\n") 18 | print ("Your number is: ", a) 19 | 20 | 21 | # Why: List and loop example 22 | # use of alt+ shift or alt + select to add changes at various places at once 23 | movieList = ["-Inception", 24 | "-The dep Unchained", 25 | "-Django Unchained ", 26 | "-The wolf of wall street ", 27 | "-SHutter island", 28 | "-Catch me if you can", 29 | ] 30 | 31 | for movie in movieList: 32 | print(f"This is {movieList}") 33 | 34 | # print using code snippet 35 | print(f"") 36 | print(f" {a}") -------------------------------------------------------------------------------- /scripts/multithreading.py: -------------------------------------------------------------------------------- 1 | import time # Why: To measure time and add delays 2 | import threading # Why: To run code in parallel threads 3 | 4 | def calculate_square(numbers): 5 | print("calculate square numbers") 6 | for n in numbers: 7 | time.sleep(1) # Why: Simulate heavy work 8 | print('square:', n*n) 9 | 10 | def calculate_cube(numbers): 11 | print("calculate cube of numbers") 12 | for n in numbers: 13 | time.sleep(1) 14 | print('cube:', n*n*n) 15 | 16 | arr = [2,3,8,9] # Why: Example data 17 | 18 | t = time.time() # Why: Track elapsed time 19 | 20 | t1 = threading.Thread(target=calculate_square, args=(arr,)) # Why: Run square in parallel 21 | t2 = threading.Thread(target=calculate_cube, args=(arr,)) # Why: Run cube in parallel 22 | 23 | t1.start() 24 | t2.start() 25 | 26 | t1.join() 27 | t2.join() 28 | 29 | print("done in : ", time.time()-t) # Why: Show speedup from threads 30 | -------------------------------------------------------------------------------- /scripts/pdf2doc.py: -------------------------------------------------------------------------------- 1 | ##pip install pdf2docx 2 | # Try installing this using pip install pdf2docx --user if you have any issues 3 | 4 | # Why: Convert PDF to DOCX for easier editing 5 | from pdf2docx import Convertor # Why: Handles PDF to Word conversion 6 | pdf_file ='ListsOfInbuiltMethods.pdf' 7 | docx_file = 'ListsOfInbuiltMethods.docx' 8 | cv = Convertor(pdf_file) 9 | cv.convertor(docx_file) # Why: Actually does the conversion 10 | cv.close # Why: Clean up resources -------------------------------------------------------------------------------- /scripts/toh.py: -------------------------------------------------------------------------------- 1 | def move(a, b): 2 | print("Move ", a, "to", b) # Why: Shows each move 3 | 4 | def TowerOfHanoi(n, A, B, C): 5 | # Why: Recursively solve for n disks 6 | if n == 1: 7 | move(A, C) # Why: Base case, move directly 8 | else: 9 | TowerOfHanoi(n-1, A, C, B) # Why: Move n-1 to spare 10 | move(A, C) # Why: Move largest disk 11 | TowerOfHanoi(n-1, B, A, C) # Why: Move n-1 on top 12 | 13 | n = int(input("Enter the number of disks")) # Why: User input for problem size 14 | TowerOfHanoi(n, "A", "B", "C") --------------------------------------------------------------------------------