├── .gitignore ├── .ipynb_checkpoints ├── Classes and Objects in Python #9-checkpoint.ipynb ├── Data Structures in Python #5-checkpoint.ipynb ├── Errors and Exceptions in Python #8-checkpoint.ipynb ├── Functions in Python #4-checkpoint.ipynb ├── Input and Output in Python #7-checkpoint.ipynb ├── Numbers, Strings and Lists with Python #2-checkpoint.ipynb ├── Python Modules #6-checkpoint.ipynb ├── Python Standard Library #10 #11 #12 #13-checkpoint.ipynb ├── Python Ultimate Tutorial #1-checkpoint.ipynb ├── Template in Python #1-checkpoint.ipynb ├── Virtual Environments and Packages in Python #14-checkpoint.ipynb └── if, for and loop statements in Python #3-checkpoint.ipynb ├── Classes and Objects in Python #9.ipynb ├── Data Structures in Python #5.ipynb ├── Errors and Exceptions in Python #8.ipynb ├── Functions in Python #4.ipynb ├── Input and Output in Python #7.ipynb ├── Numbers, Strings and Lists with Python #2.ipynb ├── Python Modules #6 ├── .DS_Store ├── .ipynb_checkpoints │ └── Python Modules #6-checkpoint.ipynb ├── Python Modules #6.ipynb ├── __pycache__ │ └── fibo.cpython-38.pyc └── fibo.py ├── Python Standard Library #10 #11 #12 #13.ipynb ├── Python Ultimate Tutorial #1.ipynb ├── README.md ├── Template in Python #1.ipynb ├── Virtual Environments and Packages in Python #14.ipynb ├── assets └── heap.png ├── if, for and loop statements in Python #3.ipynb ├── index.html ├── myFile.txt ├── myarchive.zip ├── workfile └── workfile.json /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/Classes and Objects in Python #9-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# [Amin M. Boulouma Blog](https://amboulouma.com)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Classes, Scopes, Iterators and Generators in Python #9" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "> [Reminder] 🔔\n", 22 | "- Help the creator channel reach 20k subscribers. He will keep uploading quality content for you: [Amin M. Boulouma Channel](https://www.youtube.com/channel/UCOZbokHO727qeStxeYSKMUQ?sub_confirmation=1)\n", 23 | "- This tutorial is best understood following the video playlist: [Python Ultimate Tutorial [Official Documentation]](https://www.youtube.com/watch?v=vQqisFjAnsE&list=PLpMTHmi814W0nSToTOC0Q18kREOjcJspW&index=1)" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "Hosted by Amin M. Boulouma, contact and questions: [amine.boulouma.com](https://amine.boulouma.com)\n", 31 | "- Python tutorial made simple: https://youtu.be/vQqisFjAnsE\n", 32 | "- Source code: https://amboulouma.com/python-tutorial\n", 33 | "- Github: https://github.com/amboulouma/python-ultimate-tutorial" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "### Scopes and Namespaces" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 2, 46 | "metadata": { 47 | "scrolled": true 48 | }, 49 | "outputs": [ 50 | { 51 | "name": "stdout", 52 | "output_type": "stream", 53 | "text": [ 54 | "After local assignment: test spam\n", 55 | "After nonlocal assignment: nonlocal spam\n", 56 | "After global assignment: nonlocal spam\n", 57 | "In global scope: global spam\n" 58 | ] 59 | } 60 | ], 61 | "source": [ 62 | "def scope_test():\n", 63 | " def do_local():\n", 64 | " spam = \"local spam\"\n", 65 | "\n", 66 | " def do_nonlocal():\n", 67 | " nonlocal spam\n", 68 | " spam = \"nonlocal spam\"\n", 69 | "\n", 70 | " def do_global():\n", 71 | " global spam\n", 72 | " spam = \"global spam\"\n", 73 | "\n", 74 | " spam = \"test spam\"\n", 75 | " \n", 76 | " do_local()\n", 77 | " print(\"After local assignment:\", spam)\n", 78 | " \n", 79 | " do_nonlocal()\n", 80 | " print(\"After nonlocal assignment:\", spam)\n", 81 | " \n", 82 | " do_global()\n", 83 | " print(\"After global assignment:\", spam)\n", 84 | "\n", 85 | "scope_test()\n", 86 | "print(\"In global scope:\", spam)" 87 | ] 88 | }, 89 | { 90 | "cell_type": "markdown", 91 | "metadata": {}, 92 | "source": [ 93 | "### Class Definition Syntax" 94 | ] 95 | }, 96 | { 97 | "cell_type": "raw", 98 | "metadata": {}, 99 | "source": [ 100 | "class ClassName:\n", 101 | " \n", 102 | " .\n", 103 | " .\n", 104 | " .\n", 105 | " " 106 | ] 107 | }, 108 | { 109 | "cell_type": "markdown", 110 | "metadata": {}, 111 | "source": [ 112 | "### Class Objects" 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": 4, 118 | "metadata": {}, 119 | "outputs": [], 120 | "source": [ 121 | "class MyClass:\n", 122 | " \"\"\"A simple example class\"\"\"\n", 123 | " i = 12345\n", 124 | "\n", 125 | " def f(self):\n", 126 | " return 'hello world'" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": 5, 132 | "metadata": {}, 133 | "outputs": [ 134 | { 135 | "data": { 136 | "text/plain": [ 137 | "<__main__.MyClass at 0x111cbbdc0>" 138 | ] 139 | }, 140 | "execution_count": 5, 141 | "metadata": {}, 142 | "output_type": "execute_result" 143 | } 144 | ], 145 | "source": [ 146 | "x = MyClass() #instance of class, object, x is an object of MyClass\n", 147 | "x" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": null, 153 | "metadata": {}, 154 | "outputs": [], 155 | "source": [ 156 | "x.i" 157 | ] 158 | }, 159 | { 160 | "cell_type": "code", 161 | "execution_count": null, 162 | "metadata": {}, 163 | "outputs": [], 164 | "source": [ 165 | "x.f()" 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": null, 171 | "metadata": {}, 172 | "outputs": [], 173 | "source": [ 174 | "class Complex:\n", 175 | " def __init__(self, realpart, imagpart):\n", 176 | " self.r = realpart\n", 177 | " self.i = imagpart\n", 178 | " \n", 179 | "x = Complex(3.0, -4.5)\n", 180 | "x.r, x.i" 181 | ] 182 | }, 183 | { 184 | "cell_type": "markdown", 185 | "metadata": {}, 186 | "source": [ 187 | "### Instance Objects" 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": null, 193 | "metadata": {}, 194 | "outputs": [], 195 | "source": [ 196 | "x.counter = 1\n", 197 | "while x.counter < 10:\n", 198 | " x.counter = x.counter * 2\n", 199 | "print(x.counter)\n", 200 | "del x.counter" 201 | ] 202 | }, 203 | { 204 | "cell_type": "markdown", 205 | "metadata": {}, 206 | "source": [ 207 | "### Class and Instance Variables" 208 | ] 209 | }, 210 | { 211 | "cell_type": "code", 212 | "execution_count": null, 213 | "metadata": {}, 214 | "outputs": [], 215 | "source": [ 216 | "x.f()" 217 | ] 218 | }, 219 | { 220 | "cell_type": "code", 221 | "execution_count": null, 222 | "metadata": {}, 223 | "outputs": [], 224 | "source": [ 225 | "class Dog:\n", 226 | " \n", 227 | " kind = 'canine' # class variable shared by all instances\n", 228 | "\n", 229 | " def __init__(self, name):\n", 230 | " self.name = name # instance variable unique to each instance" 231 | ] 232 | }, 233 | { 234 | "cell_type": "code", 235 | "execution_count": null, 236 | "metadata": {}, 237 | "outputs": [], 238 | "source": [ 239 | "d = Dog('Fido')\n", 240 | "e = Dog('Buddy')" 241 | ] 242 | }, 243 | { 244 | "cell_type": "code", 245 | "execution_count": null, 246 | "metadata": {}, 247 | "outputs": [], 248 | "source": [ 249 | "d.kind # shared by all dogs" 250 | ] 251 | }, 252 | { 253 | "cell_type": "code", 254 | "execution_count": null, 255 | "metadata": {}, 256 | "outputs": [], 257 | "source": [ 258 | "e.kind # shared by all dogs" 259 | ] 260 | }, 261 | { 262 | "cell_type": "code", 263 | "execution_count": null, 264 | "metadata": {}, 265 | "outputs": [], 266 | "source": [ 267 | "d.name # unique to d" 268 | ] 269 | }, 270 | { 271 | "cell_type": "code", 272 | "execution_count": null, 273 | "metadata": {}, 274 | "outputs": [], 275 | "source": [ 276 | "e.name # unique to e" 277 | ] 278 | }, 279 | { 280 | "cell_type": "code", 281 | "execution_count": null, 282 | "metadata": {}, 283 | "outputs": [], 284 | "source": [ 285 | "class Dog:\n", 286 | "\n", 287 | " tricks = [] # mistaken use of a class variable\n", 288 | "\n", 289 | " def __init__(self, name):\n", 290 | " self.name = name\n", 291 | "\n", 292 | " def add_trick(self, trick):\n", 293 | " self.tricks.append(trick)" 294 | ] 295 | }, 296 | { 297 | "cell_type": "code", 298 | "execution_count": null, 299 | "metadata": {}, 300 | "outputs": [], 301 | "source": [ 302 | "d = Dog('Fido')\n", 303 | "e = Dog('Buddy')\n", 304 | "d.add_trick('roll over')\n", 305 | "e.add_trick('play dead')" 306 | ] 307 | }, 308 | { 309 | "cell_type": "code", 310 | "execution_count": null, 311 | "metadata": {}, 312 | "outputs": [], 313 | "source": [ 314 | "d.tricks # unexpectedly shared by all dogs" 315 | ] 316 | }, 317 | { 318 | "cell_type": "code", 319 | "execution_count": null, 320 | "metadata": {}, 321 | "outputs": [], 322 | "source": [ 323 | "e.tricks" 324 | ] 325 | }, 326 | { 327 | "cell_type": "code", 328 | "execution_count": null, 329 | "metadata": {}, 330 | "outputs": [], 331 | "source": [ 332 | "class Dog:\n", 333 | "\n", 334 | " def __init__(self, name):\n", 335 | " self.name = name\n", 336 | " self.tricks = [] # creates a new empty list for each dog\n", 337 | "\n", 338 | " def add_trick(self, trick):\n", 339 | " self.tricks.append(trick)" 340 | ] 341 | }, 342 | { 343 | "cell_type": "code", 344 | "execution_count": null, 345 | "metadata": {}, 346 | "outputs": [], 347 | "source": [ 348 | "d = Dog('Fido')\n", 349 | "e = Dog('Buddy')\n", 350 | "d.add_trick('roll over')\n", 351 | "e.add_trick('play dead')" 352 | ] 353 | }, 354 | { 355 | "cell_type": "code", 356 | "execution_count": null, 357 | "metadata": {}, 358 | "outputs": [], 359 | "source": [ 360 | "d.tricks" 361 | ] 362 | }, 363 | { 364 | "cell_type": "code", 365 | "execution_count": null, 366 | "metadata": {}, 367 | "outputs": [], 368 | "source": [ 369 | "e.tricks" 370 | ] 371 | }, 372 | { 373 | "cell_type": "markdown", 374 | "metadata": {}, 375 | "source": [ 376 | "### Random Remarks" 377 | ] 378 | }, 379 | { 380 | "cell_type": "code", 381 | "execution_count": null, 382 | "metadata": {}, 383 | "outputs": [], 384 | "source": [ 385 | "class Warehouse:\n", 386 | " purpose = 'storage'\n", 387 | " region = 'west'\n", 388 | "\n", 389 | "w1 = Warehouse()\n", 390 | "print(w1.purpose, w1.region)" 391 | ] 392 | }, 393 | { 394 | "cell_type": "code", 395 | "execution_count": null, 396 | "metadata": { 397 | "scrolled": true 398 | }, 399 | "outputs": [], 400 | "source": [ 401 | "w2 = Warehouse()\n", 402 | "w2.region = 'east'\n", 403 | "print(w2.purpose, w2.region)" 404 | ] 405 | }, 406 | { 407 | "cell_type": "code", 408 | "execution_count": null, 409 | "metadata": {}, 410 | "outputs": [], 411 | "source": [ 412 | "# Function defined outside the class\n", 413 | "def f1(self, x, y):\n", 414 | " return min(x, x+y)\n", 415 | "\n", 416 | "class C:\n", 417 | " f = f1\n", 418 | "\n", 419 | " def g(self):\n", 420 | " return 'hello world'\n", 421 | "\n", 422 | " h = g" 423 | ] 424 | }, 425 | { 426 | "cell_type": "code", 427 | "execution_count": null, 428 | "metadata": {}, 429 | "outputs": [], 430 | "source": [ 431 | "class Bag:\n", 432 | " def __init__(self):\n", 433 | " self.data = []\n", 434 | "\n", 435 | " def add(self, x):\n", 436 | " self.data.append(x)\n", 437 | "\n", 438 | " def addtwice(self, x):\n", 439 | " self.add(x)\n", 440 | " self.add(x)" 441 | ] 442 | }, 443 | { 444 | "cell_type": "markdown", 445 | "metadata": {}, 446 | "source": [ 447 | "### Inheritance" 448 | ] 449 | }, 450 | { 451 | "cell_type": "raw", 452 | "metadata": {}, 453 | "source": [ 454 | "class DerivedClassName(BaseClassName):\n", 455 | " \n", 456 | " .\n", 457 | " .\n", 458 | " .\n", 459 | " " 460 | ] 461 | }, 462 | { 463 | "cell_type": "raw", 464 | "metadata": {}, 465 | "source": [ 466 | "class DerivedClassName(modname.BaseClassName):" 467 | ] 468 | }, 469 | { 470 | "cell_type": "markdown", 471 | "metadata": {}, 472 | "source": [ 473 | "### Multiple Inheritance" 474 | ] 475 | }, 476 | { 477 | "cell_type": "raw", 478 | "metadata": {}, 479 | "source": [ 480 | "class DerivedClassName(Base1, Base2, Base3):\n", 481 | " \n", 482 | " .\n", 483 | " .\n", 484 | " .\n", 485 | " " 486 | ] 487 | }, 488 | { 489 | "cell_type": "markdown", 490 | "metadata": {}, 491 | "source": [ 492 | "### Private Variables" 493 | ] 494 | }, 495 | { 496 | "cell_type": "code", 497 | "execution_count": null, 498 | "metadata": {}, 499 | "outputs": [], 500 | "source": [ 501 | "class Mapping:\n", 502 | " def __init__(self, iterable):\n", 503 | " self.items_list = []\n", 504 | " self.__update(iterable)\n", 505 | "\n", 506 | " def update(self, iterable):\n", 507 | " for item in iterable:\n", 508 | " self.items_list.append(item)\n", 509 | " # name mangling\n", 510 | " # represented by _Mapping__update\n", 511 | " __update = update # private copy of original update() method\n", 512 | "\n", 513 | "class MappingSubclass(Mapping):\n", 514 | "\n", 515 | " def update(self, keys, values):\n", 516 | " # provides new signature for update()\n", 517 | " # but does not break __init__()\n", 518 | " for item in zip(keys, values):\n", 519 | " self.items_list.append(item)" 520 | ] 521 | }, 522 | { 523 | "cell_type": "markdown", 524 | "metadata": {}, 525 | "source": [ 526 | "### Use of emplty Class" 527 | ] 528 | }, 529 | { 530 | "cell_type": "code", 531 | "execution_count": null, 532 | "metadata": {}, 533 | "outputs": [], 534 | "source": [ 535 | "class Employee:\n", 536 | " pass\n", 537 | "\n", 538 | "john = Employee() # Create an empty employee record\n", 539 | "\n", 540 | "# Fill the fields of the record\n", 541 | "john.name = 'John Doe'\n", 542 | "john.dept = 'computer lab'\n", 543 | "john.salary = 1000" 544 | ] 545 | }, 546 | { 547 | "cell_type": "markdown", 548 | "metadata": {}, 549 | "source": [ 550 | "### Iterators" 551 | ] 552 | }, 553 | { 554 | "cell_type": "code", 555 | "execution_count": null, 556 | "metadata": {}, 557 | "outputs": [], 558 | "source": [ 559 | "for element in [1, 2, 3]:\n", 560 | " print(element)\n", 561 | "for element in (1, 2, 3):\n", 562 | " print(element)\n", 563 | "for key in {'one':1, 'two':2}:\n", 564 | " print(key)\n", 565 | "for char in \"123\":\n", 566 | " print(char)\n", 567 | "for line in open(\"myfile.txt\"):\n", 568 | " print(line, end='')" 569 | ] 570 | }, 571 | { 572 | "cell_type": "code", 573 | "execution_count": null, 574 | "metadata": {}, 575 | "outputs": [], 576 | "source": [ 577 | "s = 'abc'\n", 578 | "it = iter(s)\n", 579 | "it" 580 | ] 581 | }, 582 | { 583 | "cell_type": "code", 584 | "execution_count": null, 585 | "metadata": {}, 586 | "outputs": [], 587 | "source": [ 588 | "next(it)" 589 | ] 590 | }, 591 | { 592 | "cell_type": "code", 593 | "execution_count": null, 594 | "metadata": {}, 595 | "outputs": [], 596 | "source": [ 597 | "next(it)" 598 | ] 599 | }, 600 | { 601 | "cell_type": "code", 602 | "execution_count": null, 603 | "metadata": {}, 604 | "outputs": [], 605 | "source": [ 606 | "next(it)" 607 | ] 608 | }, 609 | { 610 | "cell_type": "code", 611 | "execution_count": null, 612 | "metadata": {}, 613 | "outputs": [], 614 | "source": [ 615 | "class Reverse:\n", 616 | " \"\"\"Iterator for looping over a sequence backwards.\"\"\"\n", 617 | " def __init__(self, data):\n", 618 | " self.data = data\n", 619 | " self.index = len(data)\n", 620 | "\n", 621 | " def __iter__(self):\n", 622 | " return self\n", 623 | "\n", 624 | " def __next__(self):\n", 625 | " if self.index == 0:\n", 626 | " raise StopIteration\n", 627 | " self.index = self.index - 1\n", 628 | " return self.data[self.index]" 629 | ] 630 | }, 631 | { 632 | "cell_type": "code", 633 | "execution_count": null, 634 | "metadata": {}, 635 | "outputs": [], 636 | "source": [ 637 | "rev = Reverse('spam')\n", 638 | "iter(rev)" 639 | ] 640 | }, 641 | { 642 | "cell_type": "code", 643 | "execution_count": null, 644 | "metadata": { 645 | "scrolled": true 646 | }, 647 | "outputs": [], 648 | "source": [ 649 | "for char in rev:\n", 650 | " print(char)" 651 | ] 652 | }, 653 | { 654 | "cell_type": "markdown", 655 | "metadata": {}, 656 | "source": [ 657 | "### Generators" 658 | ] 659 | }, 660 | { 661 | "cell_type": "code", 662 | "execution_count": null, 663 | "metadata": {}, 664 | "outputs": [], 665 | "source": [ 666 | "def reverse(data):\n", 667 | " for index in range(len(data)-1, -1, -1):\n", 668 | " yield data[index]\n", 669 | "\n", 670 | "for char in reverse('golf'):\n", 671 | " print(char)" 672 | ] 673 | }, 674 | { 675 | "cell_type": "markdown", 676 | "metadata": {}, 677 | "source": [ 678 | "### Generator Expressions" 679 | ] 680 | }, 681 | { 682 | "cell_type": "code", 683 | "execution_count": null, 684 | "metadata": {}, 685 | "outputs": [], 686 | "source": [ 687 | "sum(i*i for i in range(10)) # sum of squares" 688 | ] 689 | }, 690 | { 691 | "cell_type": "code", 692 | "execution_count": null, 693 | "metadata": {}, 694 | "outputs": [], 695 | "source": [ 696 | "xvec = [10, 20, 30]\n", 697 | "yvec = [7, 5, 3]\n", 698 | "sum(x*y for x,y in zip(xvec, yvec)) # dot product" 699 | ] 700 | }, 701 | { 702 | "cell_type": "code", 703 | "execution_count": null, 704 | "metadata": {}, 705 | "outputs": [], 706 | "source": [ 707 | "with open('myFile.txt') as f:\n", 708 | " page = f.readlines()\n", 709 | " unique_words = set(word for line in page for word in line.split())\n", 710 | "\n", 711 | "print(unique_words)" 712 | ] 713 | }, 714 | { 715 | "cell_type": "code", 716 | "execution_count": null, 717 | "metadata": {}, 718 | "outputs": [], 719 | "source": [ 720 | "valedictorian = max((student.gpa, student.name) for student in graduates)" 721 | ] 722 | }, 723 | { 724 | "cell_type": "code", 725 | "execution_count": null, 726 | "metadata": {}, 727 | "outputs": [], 728 | "source": [ 729 | "data = 'golf'\n", 730 | "list(data[i] for i in range(len(data)-1, -1, -1))" 731 | ] 732 | }, 733 | { 734 | "cell_type": "code", 735 | "execution_count": null, 736 | "metadata": {}, 737 | "outputs": [], 738 | "source": [] 739 | } 740 | ], 741 | "metadata": { 742 | "kernelspec": { 743 | "display_name": "Python 3", 744 | "language": "python", 745 | "name": "python3" 746 | }, 747 | "language_info": { 748 | "codemirror_mode": { 749 | "name": "ipython", 750 | "version": 3 751 | }, 752 | "file_extension": ".py", 753 | "mimetype": "text/x-python", 754 | "name": "python", 755 | "nbconvert_exporter": "python", 756 | "pygments_lexer": "ipython3", 757 | "version": "3.8.5" 758 | } 759 | }, 760 | "nbformat": 4, 761 | "nbformat_minor": 4 762 | } 763 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/Errors and Exceptions in Python #8-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# [Amin M. Boulouma Blog](https://amboulouma.com)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Errors and Exceptions in Python #8" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "> [Reminder] 🔔\n", 22 | "- Help the creator channel reach 20k subscribers. He will keep uploading quality content for you: [Amin M. Boulouma Channel](https://www.youtube.com/channel/UCOZbokHO727qeStxeYSKMUQ?sub_confirmation=1)\n", 23 | "- This tutorial is best understood following the video playlist: [Python Ultimate Tutorial [Official Documentation]](https://www.youtube.com/watch?v=vQqisFjAnsE&list=PLpMTHmi814W0nSToTOC0Q18kREOjcJspW&index=1)\n" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "Hosted by Amin M. Boulouma, contact and questions: [amine.boulouma.com](https://amine.boulouma.com)\n", 31 | "- Python tutorial made simple: https://youtu.be/vQqisFjAnsE\n", 32 | "- Source code: https://amboulouma.com/python-tutorial\n", 33 | "- Github: https://github.com/amboulouma/python-ultimate-tutorial" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "### Syntax Errors" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 1, 46 | "metadata": {}, 47 | "outputs": [ 48 | { 49 | "ename": "SyntaxError", 50 | "evalue": "Missing parentheses in call to 'print'. Did you mean print('Hello world')? (, line 1)", 51 | "output_type": "error", 52 | "traceback": [ 53 | "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m print 'Hello world'\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('Hello world')?\n" 54 | ] 55 | } 56 | ], 57 | "source": [ 58 | "print 'Hello world'" 59 | ] 60 | }, 61 | { 62 | "cell_type": "markdown", 63 | "metadata": {}, 64 | "source": [ 65 | "## Exceptions" 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": 2, 71 | "metadata": {}, 72 | "outputs": [ 73 | { 74 | "ename": "ZeroDivisionError", 75 | "evalue": "division by zero", 76 | "output_type": "error", 77 | "traceback": [ 78 | "\u001b[0;31m-------------------------------------\u001b[0m", 79 | "\u001b[0;31mZeroDivisionError\u001b[0mTraceback (most recent call last)", 80 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;36m10\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 81 | "\u001b[0;31mZeroDivisionError\u001b[0m: division by zero" 82 | ] 83 | } 84 | ], 85 | "source": [ 86 | "10 * (1/0)" 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": 3, 92 | "metadata": {}, 93 | "outputs": [ 94 | { 95 | "ename": "NameError", 96 | "evalue": "name 'spam' is not defined", 97 | "output_type": "error", 98 | "traceback": [ 99 | "\u001b[0;31m-------------------------------------\u001b[0m", 100 | "\u001b[0;31mNameError\u001b[0mTraceback (most recent call last)", 101 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;36m4\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mspam\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 102 | "\u001b[0;31mNameError\u001b[0m: name 'spam' is not defined" 103 | ] 104 | } 105 | ], 106 | "source": [ 107 | "4 + spam*3" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": 7, 113 | "metadata": {}, 114 | "outputs": [ 115 | { 116 | "ename": "TypeError", 117 | "evalue": "can only concatenate str (not \"int\") to str", 118 | "output_type": "error", 119 | "traceback": [ 120 | "\u001b[0;31m-------------------------------------\u001b[0m", 121 | "\u001b[0;31mTypeError\u001b[0mTraceback (most recent call last)", 122 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;34m'2'\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 123 | "\u001b[0;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str" 124 | ] 125 | } 126 | ], 127 | "source": [ 128 | "'2' + 2" 129 | ] 130 | }, 131 | { 132 | "cell_type": "markdown", 133 | "metadata": {}, 134 | "source": [ 135 | "### Handling Exceptions" 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": 8, 141 | "metadata": {}, 142 | "outputs": [ 143 | { 144 | "name": "stdout", 145 | "output_type": "stream", 146 | "text": [ 147 | "Please enter a number: a\n", 148 | "Oops! That was no valid number. Try again...\n", 149 | "Please enter a number: b\n", 150 | "Oops! That was no valid number. Try again...\n", 151 | "Please enter a number: 12e\n", 152 | "Oops! That was no valid number. Try again...\n", 153 | "Please enter a number: 12\n" 154 | ] 155 | } 156 | ], 157 | "source": [ 158 | "while True:\n", 159 | " try:\n", 160 | " x = int(input(\"Please enter a number: \"))\n", 161 | " break\n", 162 | " except ValueError:\n", 163 | " print(\"Oops! That was no valid number. Try again...\")\n", 164 | " except (RuntimeError, TypeError, NameError):\n", 165 | " pass" 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": 9, 171 | "metadata": {}, 172 | "outputs": [ 173 | { 174 | "name": "stdout", 175 | "output_type": "stream", 176 | "text": [ 177 | "B\n", 178 | "C\n", 179 | "D\n" 180 | ] 181 | } 182 | ], 183 | "source": [ 184 | "class B(Exception):\n", 185 | " pass\n", 186 | "\n", 187 | "class C(B):\n", 188 | " pass\n", 189 | "\n", 190 | "class D(C):\n", 191 | " pass\n", 192 | "\n", 193 | "for cls in [B, C, D]:\n", 194 | " try:\n", 195 | " raise cls()\n", 196 | " except D:\n", 197 | " print(\"D\")\n", 198 | " except C:\n", 199 | " print(\"C\")\n", 200 | " except B:\n", 201 | " print(\"B\")" 202 | ] 203 | }, 204 | { 205 | "cell_type": "code", 206 | "execution_count": 19, 207 | "metadata": {}, 208 | "outputs": [ 209 | { 210 | "name": "stdout", 211 | "output_type": "stream", 212 | "text": [ 213 | "Unexpected error: \n" 214 | ] 215 | }, 216 | { 217 | "ename": "SyntaxError", 218 | "evalue": "None ()", 219 | "output_type": "error", 220 | "traceback": [ 221 | "Traceback \u001b[0;36m(most recent call last)\u001b[0m:\n", 222 | " File \u001b[1;32m\"/Users/admin/opt/anaconda3/lib/python3.8/site-packages/IPython/core/interactiveshell.py\"\u001b[0m, line \u001b[1;32m3418\u001b[0m, in \u001b[1;35mrun_code\u001b[0m\n exec(code_obj, self.user_global_ns, self.user_ns)\n", 223 | "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m6\u001b[0;36m, in \u001b[0;35m\u001b[0;36m\u001b[0m\n\u001b[0;31m raise SyntaxError\u001b[0m\n", 224 | "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32munknown\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\n" 225 | ] 226 | } 227 | ], 228 | "source": [ 229 | "import sys\n", 230 | "\n", 231 | "try:\n", 232 | " f = open('myfile.txt')\n", 233 | " s = f.readline()\n", 234 | " raise SyntaxError\n", 235 | " i = int(s.strip())\n", 236 | "except OSError as err:\n", 237 | " print(\"OS error: {0}\".format(err))\n", 238 | "except ValueError:\n", 239 | " print(\"Could not convert data to an integer.\")\n", 240 | "except:\n", 241 | " print(\"Unexpected error:\", sys.exc_info()[0])\n", 242 | " raise" 243 | ] 244 | }, 245 | { 246 | "cell_type": "code", 247 | "execution_count": 20, 248 | "metadata": {}, 249 | "outputs": [ 250 | { 251 | "name": "stdout", 252 | "output_type": "stream", 253 | "text": [ 254 | "cannot open -f\n", 255 | "/Users/admin/Library/Jupyter/runtime/kernel-d21e66fb-710b-4b31-9682-2e7b12647b79.json has 12 lines\n" 256 | ] 257 | } 258 | ], 259 | "source": [ 260 | "for arg in sys.argv[1:]:\n", 261 | " try:\n", 262 | " f = open(arg, 'r')\n", 263 | " except OSError:\n", 264 | " print('cannot open', arg)\n", 265 | " else:\n", 266 | " print(arg, 'has', len(f.readlines()), 'lines')\n", 267 | " f.close()" 268 | ] 269 | }, 270 | { 271 | "cell_type": "code", 272 | "execution_count": null, 273 | "metadata": {}, 274 | "outputs": [], 275 | "source": [ 276 | "try:\n", 277 | " raise Exception('spam', 'eggs')\n", 278 | "except Exception as inst:\n", 279 | " print(type(inst)) # the exception instance\n", 280 | " print(inst.args) # arguments stored in .args\n", 281 | " print(inst) # __str__ allows args to be printed directly,\n", 282 | " # but may be overridden in exception subclasses\n", 283 | " x, y = inst.args # unpack args\n", 284 | " print('x =', x)\n", 285 | " print('y =', y)" 286 | ] 287 | }, 288 | { 289 | "cell_type": "code", 290 | "execution_count": null, 291 | "metadata": {}, 292 | "outputs": [], 293 | "source": [ 294 | "def this_fails():\n", 295 | " x = 1/0\n", 296 | " \n", 297 | "try:\n", 298 | " this_fails()\n", 299 | "except ZeroDivisionError as err:\n", 300 | " print('Handling run-time error:', err)" 301 | ] 302 | }, 303 | { 304 | "cell_type": "markdown", 305 | "metadata": {}, 306 | "source": [ 307 | "### Raising Exceptions" 308 | ] 309 | }, 310 | { 311 | "cell_type": "code", 312 | "execution_count": null, 313 | "metadata": {}, 314 | "outputs": [], 315 | "source": [ 316 | "raise NameError('HiThere')" 317 | ] 318 | }, 319 | { 320 | "cell_type": "code", 321 | "execution_count": null, 322 | "metadata": {}, 323 | "outputs": [], 324 | "source": [ 325 | "raise ValueError # shorthand for 'raise ValueError()'" 326 | ] 327 | }, 328 | { 329 | "cell_type": "code", 330 | "execution_count": null, 331 | "metadata": {}, 332 | "outputs": [], 333 | "source": [ 334 | "try:\n", 335 | " raise NameError('HiThere')\n", 336 | "except NameError:\n", 337 | " print('An exception flew by!')\n", 338 | " raise" 339 | ] 340 | }, 341 | { 342 | "cell_type": "markdown", 343 | "metadata": {}, 344 | "source": [ 345 | "### Exception Chaining" 346 | ] 347 | }, 348 | { 349 | "cell_type": "code", 350 | "execution_count": null, 351 | "metadata": {}, 352 | "outputs": [], 353 | "source": [ 354 | "# exc must be exception instance or None.\n", 355 | "raise RuntimeError from exc" 356 | ] 357 | }, 358 | { 359 | "cell_type": "code", 360 | "execution_count": null, 361 | "metadata": {}, 362 | "outputs": [], 363 | "source": [ 364 | "def func():\n", 365 | " raise IOError\n", 366 | "\n", 367 | "try:\n", 368 | " func()\n", 369 | "except IOError as exc:\n", 370 | " raise RuntimeError('Failed to open database') from exc\n" 371 | ] 372 | }, 373 | { 374 | "cell_type": "code", 375 | "execution_count": null, 376 | "metadata": {}, 377 | "outputs": [], 378 | "source": [ 379 | "try:\n", 380 | " open('database.sqlite')\n", 381 | "except OSError:\n", 382 | " raise RuntimeError from None" 383 | ] 384 | }, 385 | { 386 | "cell_type": "markdown", 387 | "metadata": {}, 388 | "source": [ 389 | "### User-defined Exceptions" 390 | ] 391 | }, 392 | { 393 | "cell_type": "code", 394 | "execution_count": null, 395 | "metadata": {}, 396 | "outputs": [], 397 | "source": [ 398 | "class Error(Exception):\n", 399 | " \"\"\"Base class for exceptions in this module.\"\"\"\n", 400 | " pass\n", 401 | "\n", 402 | "class InputError(Error):\n", 403 | " \"\"\"Exception raised for errors in the input.\n", 404 | "\n", 405 | " Attributes:\n", 406 | " expression -- input expression in which the error occurred\n", 407 | " message -- explanation of the error\n", 408 | " \"\"\"\n", 409 | "\n", 410 | " def __init__(self, expression, message):\n", 411 | " self.expression = expression\n", 412 | " self.message = message\n", 413 | "\n", 414 | "class TransitionError(Error):\n", 415 | " \"\"\"Raised when an operation attempts a state transition that's not\n", 416 | " allowed.\n", 417 | "\n", 418 | " Attributes:\n", 419 | " previous -- state at beginning of transition\n", 420 | " next -- attempted new state\n", 421 | " message -- explanation of why the specific transition is not allowed\n", 422 | " \"\"\"\n", 423 | "\n", 424 | " def __init__(self, previous, next, message):\n", 425 | " self.previous = previous\n", 426 | " self.next = next\n", 427 | " self.message = message" 428 | ] 429 | }, 430 | { 431 | "cell_type": "markdown", 432 | "metadata": {}, 433 | "source": [ 434 | "### Defining Clean-up Actions" 435 | ] 436 | }, 437 | { 438 | "cell_type": "code", 439 | "execution_count": null, 440 | "metadata": {}, 441 | "outputs": [], 442 | "source": [ 443 | "try:\n", 444 | " raise KeyboardInterrupt\n", 445 | "finally:\n", 446 | " print('Goodbye, world!')" 447 | ] 448 | }, 449 | { 450 | "cell_type": "code", 451 | "execution_count": null, 452 | "metadata": {}, 453 | "outputs": [], 454 | "source": [ 455 | "def bool_return():\n", 456 | " try:\n", 457 | " return True\n", 458 | " finally:\n", 459 | " return False\n", 460 | "\n", 461 | "bool_return()" 462 | ] 463 | }, 464 | { 465 | "cell_type": "code", 466 | "execution_count": null, 467 | "metadata": {}, 468 | "outputs": [], 469 | "source": [ 470 | "def divide(x, y):\n", 471 | " try:\n", 472 | " result = x / y\n", 473 | " except ZeroDivisionError:\n", 474 | " print(\"division by zero!\")\n", 475 | " else:\n", 476 | " print(\"result is\", result)\n", 477 | " finally:\n", 478 | " print(\"executing finally clause\")" 479 | ] 480 | }, 481 | { 482 | "cell_type": "code", 483 | "execution_count": null, 484 | "metadata": {}, 485 | "outputs": [], 486 | "source": [ 487 | "divide(2, 1)" 488 | ] 489 | }, 490 | { 491 | "cell_type": "code", 492 | "execution_count": null, 493 | "metadata": {}, 494 | "outputs": [], 495 | "source": [ 496 | "divide(2, 0)" 497 | ] 498 | }, 499 | { 500 | "cell_type": "code", 501 | "execution_count": null, 502 | "metadata": {}, 503 | "outputs": [], 504 | "source": [ 505 | "divide(\"2\", \"1\")" 506 | ] 507 | } 508 | ], 509 | "metadata": { 510 | "kernelspec": { 511 | "display_name": "Python 3", 512 | "language": "python", 513 | "name": "python3" 514 | }, 515 | "language_info": { 516 | "codemirror_mode": { 517 | "name": "ipython", 518 | "version": 3 519 | }, 520 | "file_extension": ".py", 521 | "mimetype": "text/x-python", 522 | "name": "python", 523 | "nbconvert_exporter": "python", 524 | "pygments_lexer": "ipython3", 525 | "version": "3.8.5" 526 | } 527 | }, 528 | "nbformat": 4, 529 | "nbformat_minor": 4 530 | } 531 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/Input and Output in Python #7-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# [Amin M. Boulouma Blog](https://amboulouma.com)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Input and Output in Python #7" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "> [Reminder] 🔔\n", 22 | "- Help the creator channel reach 20k subscribers. He will keep uploading quality content for you: [Amin M. Boulouma Channel](https://www.youtube.com/channel/UCOZbokHO727qeStxeYSKMUQ?sub_confirmation=1)\n", 23 | "- This tutorial is best understood following the video playlist: [Python Ultimate Tutorial [Official Documentation]](https://www.youtube.com/watch?v=vQqisFjAnsE&list=PLpMTHmi814W0nSToTOC0Q18kREOjcJspW&index=1)\n" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "Hosted by Amin M. Boulouma, contact and questions: [amine.boulouma.com](https://amine.boulouma.com)\n", 31 | "- Python tutorial made simple: https://youtu.be/vQqisFjAnsE\n", 32 | "- Source code: https://amboulouma.com/python-tutorial\n", 33 | "- Github: https://github.com/amboulouma/python-ultimate-tutorial" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "### Output formatting" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 1, 46 | "metadata": {}, 47 | "outputs": [ 48 | { 49 | "data": { 50 | "text/plain": [ 51 | "'Results of the 2016 Referendum'" 52 | ] 53 | }, 54 | "execution_count": 1, 55 | "metadata": {}, 56 | "output_type": "execute_result" 57 | } 58 | ], 59 | "source": [ 60 | "year = 2016\n", 61 | "event = 'Referendum'\n", 62 | "f'Results of the {year} {event}'" 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": 3, 68 | "metadata": {}, 69 | "outputs": [ 70 | { 71 | "data": { 72 | "text/plain": [ 73 | "'42572654 YES votes 49.673%'" 74 | ] 75 | }, 76 | "execution_count": 3, 77 | "metadata": {}, 78 | "output_type": "execute_result" 79 | } 80 | ], 81 | "source": [ 82 | "yes_votes = 42_572_654\n", 83 | "no_votes = 43_132_495\n", 84 | "percentage = yes_votes / (yes_votes + no_votes)\n", 85 | "'{} YES votes {:2.3%}'.format(yes_votes, percentage)" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": 4, 91 | "metadata": {}, 92 | "outputs": [ 93 | { 94 | "data": { 95 | "text/plain": [ 96 | "'Hello, world.'" 97 | ] 98 | }, 99 | "execution_count": 4, 100 | "metadata": {}, 101 | "output_type": "execute_result" 102 | } 103 | ], 104 | "source": [ 105 | "s = 'Hello, world.'\n", 106 | "str(s)" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": 5, 112 | "metadata": {}, 113 | "outputs": [ 114 | { 115 | "data": { 116 | "text/plain": [ 117 | "\"'Hello, world.'\"" 118 | ] 119 | }, 120 | "execution_count": 5, 121 | "metadata": {}, 122 | "output_type": "execute_result" 123 | } 124 | ], 125 | "source": [ 126 | "repr(s)" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": 6, 132 | "metadata": {}, 133 | "outputs": [ 134 | { 135 | "data": { 136 | "text/plain": [ 137 | "'0.14285714285714285'" 138 | ] 139 | }, 140 | "execution_count": 6, 141 | "metadata": {}, 142 | "output_type": "execute_result" 143 | } 144 | ], 145 | "source": [ 146 | "str(1/7)" 147 | ] 148 | }, 149 | { 150 | "cell_type": "code", 151 | "execution_count": 7, 152 | "metadata": {}, 153 | "outputs": [ 154 | { 155 | "name": "stdout", 156 | "output_type": "stream", 157 | "text": [ 158 | "The value of x is 32.5, and y is 40000...\n" 159 | ] 160 | } 161 | ], 162 | "source": [ 163 | "x = 10 * 3.25\n", 164 | "y = 200 * 200\n", 165 | "s = 'The value of x is ' + str(x) + ', and y is ' + str(y) + '...'\n", 166 | "print(s)" 167 | ] 168 | }, 169 | { 170 | "cell_type": "code", 171 | "execution_count": 8, 172 | "metadata": {}, 173 | "outputs": [ 174 | { 175 | "name": "stdout", 176 | "output_type": "stream", 177 | "text": [ 178 | "hello, world\n", 179 | "\n", 180 | "'hello, world\\n'\n" 181 | ] 182 | } 183 | ], 184 | "source": [ 185 | "# The repr() of a string adds string quotes and backslashes:\n", 186 | "hello = 'hello, world\\n'\n", 187 | "hellos = repr(hello)\n", 188 | "print(hello)\n", 189 | "print(hellos)" 190 | ] 191 | }, 192 | { 193 | "cell_type": "code", 194 | "execution_count": 9, 195 | "metadata": {}, 196 | "outputs": [ 197 | { 198 | "data": { 199 | "text/plain": [ 200 | "\"(32.5, 40000, ('spam', 'eggs'))\"" 201 | ] 202 | }, 203 | "execution_count": 9, 204 | "metadata": {}, 205 | "output_type": "execute_result" 206 | } 207 | ], 208 | "source": [ 209 | "# The argument to repr() may be any Python object:\n", 210 | "repr((x, y, ('spam', 'eggs')))" 211 | ] 212 | }, 213 | { 214 | "cell_type": "markdown", 215 | "metadata": {}, 216 | "source": [ 217 | "### Formatted String Literals" 218 | ] 219 | }, 220 | { 221 | "cell_type": "code", 222 | "execution_count": 12, 223 | "metadata": {}, 224 | "outputs": [ 225 | { 226 | "name": "stdout", 227 | "output_type": "stream", 228 | "text": [ 229 | "The value of pi is approximately 3.14.\n" 230 | ] 231 | } 232 | ], 233 | "source": [ 234 | "import math\n", 235 | "print(f'The value of pi is approximately {math.pi:.2f}.')" 236 | ] 237 | }, 238 | { 239 | "cell_type": "code", 240 | "execution_count": 15, 241 | "metadata": {}, 242 | "outputs": [ 243 | { 244 | "name": "stdout", 245 | "output_type": "stream", 246 | "text": [ 247 | "Sjoerd ==> 4127\n", 248 | "Jack ==> 4098\n", 249 | "Dcab ==> 7678\n" 250 | ] 251 | } 252 | ], 253 | "source": [ 254 | "table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 7678}\n", 255 | "for name, phone in table.items():\n", 256 | " print(f'{name:6} ==> {phone:5d}')" 257 | ] 258 | }, 259 | { 260 | "cell_type": "code", 261 | "execution_count": 16, 262 | "metadata": {}, 263 | "outputs": [ 264 | { 265 | "name": "stdout", 266 | "output_type": "stream", 267 | "text": [ 268 | "My hovercraft is full of eels.\n" 269 | ] 270 | } 271 | ], 272 | "source": [ 273 | "animals = 'eels'\n", 274 | "print(f'My hovercraft is full of {animals}.')" 275 | ] 276 | }, 277 | { 278 | "cell_type": "code", 279 | "execution_count": 17, 280 | "metadata": { 281 | "scrolled": false 282 | }, 283 | "outputs": [ 284 | { 285 | "name": "stdout", 286 | "output_type": "stream", 287 | "text": [ 288 | "My hovercraft is full of 'eels'.\n" 289 | ] 290 | } 291 | ], 292 | "source": [ 293 | "print(f'My hovercraft is full of {animals!r}.')" 294 | ] 295 | }, 296 | { 297 | "cell_type": "code", 298 | "execution_count": 18, 299 | "metadata": {}, 300 | "outputs": [ 301 | { 302 | "name": "stdout", 303 | "output_type": "stream", 304 | "text": [ 305 | "My hovercraft is full of 'eels'.\n" 306 | ] 307 | } 308 | ], 309 | "source": [ 310 | "print('My hovercraft is full of ' + repr(animals) + '.')" 311 | ] 312 | }, 313 | { 314 | "cell_type": "markdown", 315 | "metadata": {}, 316 | "source": [ 317 | "### The String format() Method" 318 | ] 319 | }, 320 | { 321 | "cell_type": "code", 322 | "execution_count": 19, 323 | "metadata": {}, 324 | "outputs": [ 325 | { 326 | "name": "stdout", 327 | "output_type": "stream", 328 | "text": [ 329 | "We are the knights who say \"Ni!\"\n" 330 | ] 331 | } 332 | ], 333 | "source": [ 334 | "print('We are the {} who say \"{}!\"'.format('knights', 'Ni'))" 335 | ] 336 | }, 337 | { 338 | "cell_type": "code", 339 | "execution_count": 20, 340 | "metadata": {}, 341 | "outputs": [ 342 | { 343 | "name": "stdout", 344 | "output_type": "stream", 345 | "text": [ 346 | "spam and eggs\n" 347 | ] 348 | } 349 | ], 350 | "source": [ 351 | "print('{0} and {1}'.format('spam', 'eggs'))" 352 | ] 353 | }, 354 | { 355 | "cell_type": "code", 356 | "execution_count": 21, 357 | "metadata": {}, 358 | "outputs": [ 359 | { 360 | "name": "stdout", 361 | "output_type": "stream", 362 | "text": [ 363 | "eggs and spam\n" 364 | ] 365 | } 366 | ], 367 | "source": [ 368 | "print('{1} and {0}'.format('spam', 'eggs'))" 369 | ] 370 | }, 371 | { 372 | "cell_type": "code", 373 | "execution_count": 22, 374 | "metadata": {}, 375 | "outputs": [ 376 | { 377 | "name": "stdout", 378 | "output_type": "stream", 379 | "text": [ 380 | "This spam is absolutely horrible.\n" 381 | ] 382 | } 383 | ], 384 | "source": [ 385 | "print('This {food} is {adjective}.'.format(\n", 386 | " food='spam', adjective='absolutely horrible'))" 387 | ] 388 | }, 389 | { 390 | "cell_type": "code", 391 | "execution_count": 23, 392 | "metadata": {}, 393 | "outputs": [ 394 | { 395 | "name": "stdout", 396 | "output_type": "stream", 397 | "text": [ 398 | "The story of Bill, Manfred, and Georg.\n" 399 | ] 400 | } 401 | ], 402 | "source": [ 403 | "print('The story of {0}, {1}, and {other}.'.format('Bill', 'Manfred',\n", 404 | " other='Georg'))" 405 | ] 406 | }, 407 | { 408 | "cell_type": "code", 409 | "execution_count": 24, 410 | "metadata": {}, 411 | "outputs": [ 412 | { 413 | "name": "stdout", 414 | "output_type": "stream", 415 | "text": [ 416 | "Jack: 4098; Sjoerd: 4127; Dcab: 8637678\n" 417 | ] 418 | } 419 | ], 420 | "source": [ 421 | "table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 8637678}\n", 422 | "print('Jack: {Jack:d}; Sjoerd: {Sjoerd:d}; Dcab: {Dcab:d}'.format(**table))" 423 | ] 424 | }, 425 | { 426 | "cell_type": "code", 427 | "execution_count": 26, 428 | "metadata": {}, 429 | "outputs": [ 430 | { 431 | "name": "stdout", 432 | "output_type": "stream", 433 | "text": [ 434 | " 1 1 1 1 1 1\n", 435 | " 2 4 8 16 32 64\n", 436 | " 3 9 27 81 243 729\n", 437 | " 4 16 64 256 1024 4096\n", 438 | " 5 25 125 625 3125 15625\n", 439 | " 6 36 216 1296 7776 46656\n", 440 | " 7 49 343 2401 16807 117649\n", 441 | " 8 64 512 4096 32768 262144\n", 442 | " 9 81 729 6561 59049 531441\n", 443 | "10 100 1000 10000 100000 1000000\n" 444 | ] 445 | } 446 | ], 447 | "source": [ 448 | " for x in range(1, 11):\n", 449 | " print('{0:2d} {1:3d} {2:4d} {3:5d} {4:6d} {5:7d}'.format(x, x*x, x*x*x, x**4, x**5, x**6))" 450 | ] 451 | }, 452 | { 453 | "cell_type": "markdown", 454 | "metadata": {}, 455 | "source": [ 456 | "### Manual String Formatting" 457 | ] 458 | }, 459 | { 460 | "cell_type": "code", 461 | "execution_count": 30, 462 | "metadata": {}, 463 | "outputs": [ 464 | { 465 | "name": "stdout", 466 | "output_type": "stream", 467 | "text": [ 468 | " 1 1 1 1\n", 469 | " 2 4 8 16\n", 470 | " 3 9 27 81\n", 471 | " 4 16 64 256\n", 472 | " 5 25 125 625\n", 473 | " 6 36 216 1296\n", 474 | " 7 49 343 2401\n", 475 | " 8 64 512 4096\n", 476 | " 9 81 729 6561\n", 477 | "10 100 1000 10000\n" 478 | ] 479 | } 480 | ], 481 | "source": [ 482 | "for x in range(1, 11):\n", 483 | " print(repr(x).rjust(2), repr(x*x).rjust(3), end=' ')\n", 484 | " # Note use of 'end' on previous line\n", 485 | " print(repr(x*x*x).rjust(4), end = ' ')\n", 486 | " \n", 487 | " print(repr(x*x*x*x).rjust(5))" 488 | ] 489 | }, 490 | { 491 | "cell_type": "code", 492 | "execution_count": 32, 493 | "metadata": {}, 494 | "outputs": [ 495 | { 496 | "data": { 497 | "text/plain": [ 498 | "'0000000012'" 499 | ] 500 | }, 501 | "execution_count": 32, 502 | "metadata": {}, 503 | "output_type": "execute_result" 504 | } 505 | ], 506 | "source": [ 507 | "'12'.zfill(10)" 508 | ] 509 | }, 510 | { 511 | "cell_type": "code", 512 | "execution_count": 33, 513 | "metadata": {}, 514 | "outputs": [ 515 | { 516 | "data": { 517 | "text/plain": [ 518 | "'-003.14'" 519 | ] 520 | }, 521 | "execution_count": 33, 522 | "metadata": {}, 523 | "output_type": "execute_result" 524 | } 525 | ], 526 | "source": [ 527 | "'-3.14'.zfill(7)" 528 | ] 529 | }, 530 | { 531 | "cell_type": "code", 532 | "execution_count": 34, 533 | "metadata": {}, 534 | "outputs": [ 535 | { 536 | "data": { 537 | "text/plain": [ 538 | "'3.14159265359'" 539 | ] 540 | }, 541 | "execution_count": 34, 542 | "metadata": {}, 543 | "output_type": "execute_result" 544 | } 545 | ], 546 | "source": [ 547 | "'3.14159265359'.zfill(5)" 548 | ] 549 | }, 550 | { 551 | "cell_type": "markdown", 552 | "metadata": {}, 553 | "source": [ 554 | "### Old string formatting" 555 | ] 556 | }, 557 | { 558 | "cell_type": "code", 559 | "execution_count": 35, 560 | "metadata": {}, 561 | "outputs": [ 562 | { 563 | "name": "stdout", 564 | "output_type": "stream", 565 | "text": [ 566 | "The value of pi is approximately 3.142.\n" 567 | ] 568 | } 569 | ], 570 | "source": [ 571 | "import math\n", 572 | "print('The value of pi is approximately %5.3f.' % math.pi)" 573 | ] 574 | }, 575 | { 576 | "cell_type": "markdown", 577 | "metadata": {}, 578 | "source": [ 579 | "### Reading and Writing Files" 580 | ] 581 | }, 582 | { 583 | "cell_type": "code", 584 | "execution_count": 40, 585 | "metadata": {}, 586 | "outputs": [], 587 | "source": [ 588 | "f = open('workfile', 'w')" 589 | ] 590 | }, 591 | { 592 | "cell_type": "code", 593 | "execution_count": 43, 594 | "metadata": {}, 595 | "outputs": [], 596 | "source": [ 597 | "with open('workfile') as f:\n", 598 | " read_data = f.read()" 599 | ] 600 | }, 601 | { 602 | "cell_type": "code", 603 | "execution_count": 44, 604 | "metadata": {}, 605 | "outputs": [ 606 | { 607 | "data": { 608 | "text/plain": [ 609 | "True" 610 | ] 611 | }, 612 | "execution_count": 44, 613 | "metadata": {}, 614 | "output_type": "execute_result" 615 | } 616 | ], 617 | "source": [ 618 | "f.closed" 619 | ] 620 | }, 621 | { 622 | "cell_type": "code", 623 | "execution_count": 42, 624 | "metadata": {}, 625 | "outputs": [ 626 | { 627 | "ename": "ValueError", 628 | "evalue": "I/O operation on closed file.", 629 | "output_type": "error", 630 | "traceback": [ 631 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 632 | "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", 633 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclose\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 634 | "\u001b[0;31mValueError\u001b[0m: I/O operation on closed file." 635 | ] 636 | } 637 | ], 638 | "source": [ 639 | "f.close()\n", 640 | "f.read()" 641 | ] 642 | }, 643 | { 644 | "cell_type": "markdown", 645 | "metadata": {}, 646 | "source": [ 647 | "### Methods of File Objects" 648 | ] 649 | }, 650 | { 651 | "cell_type": "code", 652 | "execution_count": 45, 653 | "metadata": {}, 654 | "outputs": [], 655 | "source": [ 656 | "with open('workfile', 'w') as f:\n", 657 | " f.write('This is the first line of the file.\\n')\n", 658 | " f.write('This is the second line of the file.\\n')\n", 659 | " " 660 | ] 661 | }, 662 | { 663 | "cell_type": "code", 664 | "execution_count": 46, 665 | "metadata": {}, 666 | "outputs": [ 667 | { 668 | "name": "stdout", 669 | "output_type": "stream", 670 | "text": [ 671 | "f.read 1 This is the first line of the file.\n", 672 | "This is the second line of the file.\n", 673 | "\n", 674 | "f.read 2 \n" 675 | ] 676 | } 677 | ], 678 | "source": [ 679 | "with open('workfile') as f:\n", 680 | " print('f.read 1', f.read())\n", 681 | " print('f.read 2', f.read())\n" 682 | ] 683 | }, 684 | { 685 | "cell_type": "code", 686 | "execution_count": 49, 687 | "metadata": {}, 688 | "outputs": [ 689 | { 690 | "name": "stdout", 691 | "output_type": "stream", 692 | "text": [ 693 | "['This is the first line of the file.\\n', 'This is the second line of the file.\\n']\n", 694 | "f.readline 1 \n", 695 | "f.readline 2 \n" 696 | ] 697 | } 698 | ], 699 | "source": [ 700 | "with open('workfile') as f:\n", 701 | " print(f.readlines())\n", 702 | " print('f.readline 1', f.readline())\n", 703 | " print('f.readline 2', f.readline())" 704 | ] 705 | }, 706 | { 707 | "cell_type": "code", 708 | "execution_count": null, 709 | "metadata": {}, 710 | "outputs": [], 711 | "source": [ 712 | "with open('workfile') as f:\n", 713 | " for line in f:\n", 714 | " print(line, end='')" 715 | ] 716 | }, 717 | { 718 | "cell_type": "code", 719 | "execution_count": null, 720 | "metadata": {}, 721 | "outputs": [], 722 | "source": [ 723 | "with open('workfile', 'w') as f:\n", 724 | " value = ('the answer', 42)\n", 725 | " s = str(value) # convert the tuple to string\n", 726 | " print(f.write(s)) # return the file current position" 727 | ] 728 | }, 729 | { 730 | "cell_type": "markdown", 731 | "metadata": {}, 732 | "source": [ 733 | "### Saving structured data with json" 734 | ] 735 | }, 736 | { 737 | "cell_type": "code", 738 | "execution_count": null, 739 | "metadata": {}, 740 | "outputs": [], 741 | "source": [ 742 | "import json\n", 743 | "x = [1, 'simple', 'list']\n", 744 | "json.dumps(x)" 745 | ] 746 | }, 747 | { 748 | "cell_type": "code", 749 | "execution_count": null, 750 | "metadata": {}, 751 | "outputs": [], 752 | "source": [ 753 | "with open('workfile', 'w') as f:\n", 754 | " json.dump(x, f)" 755 | ] 756 | }, 757 | { 758 | "cell_type": "code", 759 | "execution_count": null, 760 | "metadata": {}, 761 | "outputs": [], 762 | "source": [ 763 | "with open('workfile', 'r') as f:\n", 764 | " x = json.load(f)" 765 | ] 766 | }, 767 | { 768 | "cell_type": "code", 769 | "execution_count": null, 770 | "metadata": {}, 771 | "outputs": [], 772 | "source": [ 773 | "x" 774 | ] 775 | } 776 | ], 777 | "metadata": { 778 | "kernelspec": { 779 | "display_name": "Python 3", 780 | "language": "python", 781 | "name": "python3" 782 | }, 783 | "language_info": { 784 | "codemirror_mode": { 785 | "name": "ipython", 786 | "version": 3 787 | }, 788 | "file_extension": ".py", 789 | "mimetype": "text/x-python", 790 | "name": "python", 791 | "nbconvert_exporter": "python", 792 | "pygments_lexer": "ipython3", 793 | "version": "3.8.5" 794 | } 795 | }, 796 | "nbformat": 4, 797 | "nbformat_minor": 4 798 | } 799 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/Python Modules #6-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Amin M. Boulouma Blog" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Template in Python #1" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "Hosted by Amin M. Boulouma, contact and questions: [amine.boulouma.com](https://amine.boulouma.com)\n", 22 | "- Python tutorial made simple: https://www.youtube.com/channel/UCOZbokHO727qeStxeYSKMUQ\n", 23 | "- Source code: https://amboulouma.com/python-tutorial\n", 24 | "- Github: https://github.com/amboulouma/python-complete-tutorial-made-simple" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": {}, 30 | "source": [ 31 | "### Template" 32 | ] 33 | } 34 | ], 35 | "metadata": { 36 | "kernelspec": { 37 | "display_name": "Python 3", 38 | "language": "python", 39 | "name": "python3" 40 | }, 41 | "language_info": { 42 | "codemirror_mode": { 43 | "name": "ipython", 44 | "version": 3 45 | }, 46 | "file_extension": ".py", 47 | "mimetype": "text/x-python", 48 | "name": "python", 49 | "nbconvert_exporter": "python", 50 | "pygments_lexer": "ipython3", 51 | "version": "3.8.5" 52 | } 53 | }, 54 | "nbformat": 4, 55 | "nbformat_minor": 4 56 | } 57 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/Python Standard Library #10 #11 #12 #13-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# [Amin M. Boulouma Blog](https://amboulouma.com)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## OS, Regex, Internet and Math in Python #10" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "> [Reminder] 🔔\n", 22 | "- Help the creator channel reach 20k subscribers. He will keep uploading quality content for you: [Amin M. Boulouma Channel](https://www.youtube.com/channel/UCOZbokHO727qeStxeYSKMUQ?sub_confirmation=1)\n", 23 | "- This tutorial is best understood following the video playlist: [Python Ultimate Tutorial [Official Documentation]](https://www.youtube.com/watch?v=vQqisFjAnsE&list=PLpMTHmi814W0nSToTOC0Q18kREOjcJspW&index=1)" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "Hosted by Amin M. Boulouma, contact and questions: [amine.boulouma.com](https://amine.boulouma.com)\n", 31 | "- Python tutorial made simple: https://youtu.be/vQqisFjAnsE\n", 32 | "- Source code: https://amboulouma.com/python-tutorial\n", 33 | "- Github: https://github.com/amboulouma/python-ultimate-tutorial" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "### Operating System Interface" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": null, 46 | "metadata": {}, 47 | "outputs": [], 48 | "source": [ 49 | "import os\n", 50 | "\n", 51 | "os.getcwd() " 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": null, 57 | "metadata": {}, 58 | "outputs": [], 59 | "source": [ 60 | "os.chdir('/Users/admin/temp') # Change current working directory" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": null, 66 | "metadata": {}, 67 | "outputs": [], 68 | "source": [ 69 | "os.system('mkdir tempdir') # Run the command mkdir in the system shell" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": null, 75 | "metadata": { 76 | "scrolled": false 77 | }, 78 | "outputs": [], 79 | "source": [ 80 | "dir(os)" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": null, 86 | "metadata": { 87 | "scrolled": false 88 | }, 89 | "outputs": [], 90 | "source": [ 91 | "help(os)" 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": null, 97 | "metadata": {}, 98 | "outputs": [], 99 | "source": [ 100 | "import shutil\n", 101 | "\n", 102 | "shutil.copyfile('pyedit.py', 'pyedit-copy.py')" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": null, 108 | "metadata": {}, 109 | "outputs": [], 110 | "source": [ 111 | "shutil.move('pyedit.py', 'tempdir')" 112 | ] 113 | }, 114 | { 115 | "cell_type": "markdown", 116 | "metadata": {}, 117 | "source": [ 118 | "### File Wildcards" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": null, 124 | "metadata": {}, 125 | "outputs": [], 126 | "source": [ 127 | "import glob\n", 128 | "\n", 129 | "glob.glob('*.py')" 130 | ] 131 | }, 132 | { 133 | "cell_type": "markdown", 134 | "metadata": {}, 135 | "source": [ 136 | "### Command Line Arguments" 137 | ] 138 | }, 139 | { 140 | "cell_type": "code", 141 | "execution_count": null, 142 | "metadata": {}, 143 | "outputs": [], 144 | "source": [ 145 | "import sys\n", 146 | "print(sys.argv)" 147 | ] 148 | }, 149 | { 150 | "cell_type": "markdown", 151 | "metadata": {}, 152 | "source": [ 153 | "### Error Output Redirection and Program Termination" 154 | ] 155 | }, 156 | { 157 | "cell_type": "code", 158 | "execution_count": null, 159 | "metadata": {}, 160 | "outputs": [], 161 | "source": [ 162 | "sys.stderr.write('Warning, log file not found starting a new one\\n')" 163 | ] 164 | }, 165 | { 166 | "cell_type": "markdown", 167 | "metadata": {}, 168 | "source": [ 169 | "### String Pattern Matching" 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": null, 175 | "metadata": {}, 176 | "outputs": [], 177 | "source": [ 178 | "import re\n", 179 | "\n", 180 | "re.findall(r'\\bf[a-z]*', 'which foot or hand fell fastest')" 181 | ] 182 | }, 183 | { 184 | "cell_type": "code", 185 | "execution_count": null, 186 | "metadata": { 187 | "scrolled": true 188 | }, 189 | "outputs": [], 190 | "source": [ 191 | "re.sub(r'(\\b[a-z]+) \\1', r'\\1', 'cat in the the hat')" 192 | ] 193 | }, 194 | { 195 | "cell_type": "code", 196 | "execution_count": null, 197 | "metadata": {}, 198 | "outputs": [], 199 | "source": [ 200 | "'tea for too'.replace('too', 'two')" 201 | ] 202 | }, 203 | { 204 | "cell_type": "markdown", 205 | "metadata": {}, 206 | "source": [ 207 | "### Mathematics" 208 | ] 209 | }, 210 | { 211 | "cell_type": "code", 212 | "execution_count": null, 213 | "metadata": {}, 214 | "outputs": [], 215 | "source": [ 216 | "import math\n", 217 | "\n", 218 | "math.cos(math.pi / 4)" 219 | ] 220 | }, 221 | { 222 | "cell_type": "code", 223 | "execution_count": null, 224 | "metadata": {}, 225 | "outputs": [], 226 | "source": [ 227 | "math.log(1024, 2)" 228 | ] 229 | }, 230 | { 231 | "cell_type": "code", 232 | "execution_count": null, 233 | "metadata": {}, 234 | "outputs": [], 235 | "source": [ 236 | "import random\n", 237 | "\n", 238 | "random.choice(['apple', 'pear', 'banana'])" 239 | ] 240 | }, 241 | { 242 | "cell_type": "code", 243 | "execution_count": null, 244 | "metadata": {}, 245 | "outputs": [], 246 | "source": [ 247 | "random.sample(range(100), 10) # sampling without replacement" 248 | ] 249 | }, 250 | { 251 | "cell_type": "code", 252 | "execution_count": null, 253 | "metadata": {}, 254 | "outputs": [], 255 | "source": [ 256 | "random.random() # random float" 257 | ] 258 | }, 259 | { 260 | "cell_type": "code", 261 | "execution_count": null, 262 | "metadata": {}, 263 | "outputs": [], 264 | "source": [ 265 | "random.randrange(6) # random integer chosen from range(6)" 266 | ] 267 | }, 268 | { 269 | "cell_type": "code", 270 | "execution_count": null, 271 | "metadata": {}, 272 | "outputs": [], 273 | "source": [ 274 | "import statistics\n", 275 | "\n", 276 | "data = [2.75, 1.75, 1.25, 0.25, 0.5, 1.25, 3.5]\n", 277 | "statistics.mean(data)" 278 | ] 279 | }, 280 | { 281 | "cell_type": "code", 282 | "execution_count": null, 283 | "metadata": {}, 284 | "outputs": [], 285 | "source": [ 286 | "statistics.median(data)" 287 | ] 288 | }, 289 | { 290 | "cell_type": "code", 291 | "execution_count": null, 292 | "metadata": {}, 293 | "outputs": [], 294 | "source": [ 295 | "statistics.variance(data)" 296 | ] 297 | }, 298 | { 299 | "cell_type": "markdown", 300 | "metadata": {}, 301 | "source": [ 302 | "### Internet Access" 303 | ] 304 | }, 305 | { 306 | "cell_type": "code", 307 | "execution_count": null, 308 | "metadata": {}, 309 | "outputs": [], 310 | "source": [ 311 | "from urllib.request import urlopen\n", 312 | "\n", 313 | "with urlopen('https://github.com/amboulouma/python-ultimate-tutorial') as response:\n", 314 | " for line in response:\n", 315 | " line = line.decode('utf-8') # Decoding the binary data to text.\n", 316 | " if 'python' in line or 'Python' in line: # look for Eastern Time\n", 317 | " print(line)" 318 | ] 319 | }, 320 | { 321 | "cell_type": "code", 322 | "execution_count": null, 323 | "metadata": {}, 324 | "outputs": [], 325 | "source": [ 326 | "import smtplib\n", 327 | "\n", 328 | "server = smtplib.SMTP('localhost') # server running needed here\n", 329 | "server.sendmail('amine@boulouma.com', 'contact@amboulouma.com',\n", 330 | " \"\"\"To: jcaesar@example.org\n", 331 | " From: soothsayer@example.org\n", 332 | "\n", 333 | " Beware the Ides of March.\n", 334 | " \"\"\"\n", 335 | " )\n", 336 | "server.quit()" 337 | ] 338 | }, 339 | { 340 | "cell_type": "markdown", 341 | "metadata": {}, 342 | "source": [ 343 | "## Dates, Compression and Performance Python Standard Library 1 #11" 344 | ] 345 | }, 346 | { 347 | "cell_type": "markdown", 348 | "metadata": {}, 349 | "source": [ 350 | "## Dates and Times" 351 | ] 352 | }, 353 | { 354 | "cell_type": "code", 355 | "execution_count": null, 356 | "metadata": {}, 357 | "outputs": [], 358 | "source": [ 359 | "# dates are easily constructed and formatted\n", 360 | "from datetime import date\n", 361 | "now = date.today()\n", 362 | "now" 363 | ] 364 | }, 365 | { 366 | "cell_type": "code", 367 | "execution_count": null, 368 | "metadata": {}, 369 | "outputs": [], 370 | "source": [ 371 | "now.strftime(\"%m-%d-%y. %d %b %Y is a %A on the %d day of %B.\")" 372 | ] 373 | }, 374 | { 375 | "cell_type": "code", 376 | "execution_count": null, 377 | "metadata": {}, 378 | "outputs": [], 379 | "source": [ 380 | "# dates support calendar arithmetic\n", 381 | "birthday = date(1995, 11, 18)\n", 382 | "age = now - birthday\n", 383 | "age.days" 384 | ] 385 | }, 386 | { 387 | "cell_type": "markdown", 388 | "metadata": {}, 389 | "source": [ 390 | "### Data Compression" 391 | ] 392 | }, 393 | { 394 | "cell_type": "markdown", 395 | "metadata": {}, 396 | "source": [ 397 | "Common data archiving and compression formats are directly supported by modules including: zlib, gzip, bz2, lzma, zipfile and tarfile.Performance Measurement" 398 | ] 399 | }, 400 | { 401 | "cell_type": "code", 402 | "execution_count": null, 403 | "metadata": {}, 404 | "outputs": [], 405 | "source": [ 406 | "import zlib\n", 407 | "\n", 408 | "s = b'witch which has which witches wrist watch'\n", 409 | "len(s)" 410 | ] 411 | }, 412 | { 413 | "cell_type": "code", 414 | "execution_count": null, 415 | "metadata": {}, 416 | "outputs": [], 417 | "source": [ 418 | "t = zlib.compress(s)\n", 419 | "len(t)" 420 | ] 421 | }, 422 | { 423 | "cell_type": "code", 424 | "execution_count": null, 425 | "metadata": {}, 426 | "outputs": [], 427 | "source": [ 428 | "zlib.decompress(t)" 429 | ] 430 | }, 431 | { 432 | "cell_type": "code", 433 | "execution_count": null, 434 | "metadata": { 435 | "scrolled": true 436 | }, 437 | "outputs": [], 438 | "source": [ 439 | "zlib.crc32(s)" 440 | ] 441 | }, 442 | { 443 | "cell_type": "markdown", 444 | "metadata": {}, 445 | "source": [ 446 | "## Performance Measurement" 447 | ] 448 | }, 449 | { 450 | "cell_type": "markdown", 451 | "metadata": {}, 452 | "source": [ 453 | "In contrast to timeit’s fine level of granularity, the **profile** and **pstats** modules provide tools for identifying time critical sections in larger blocks of code." 454 | ] 455 | }, 456 | { 457 | "cell_type": "code", 458 | "execution_count": null, 459 | "metadata": {}, 460 | "outputs": [], 461 | "source": [ 462 | "from timeit import Timer\n", 463 | "Timer('t=a; a=b; b=t', 'a=1; b=2').timeit()" 464 | ] 465 | }, 466 | { 467 | "cell_type": "code", 468 | "execution_count": null, 469 | "metadata": { 470 | "scrolled": true 471 | }, 472 | "outputs": [], 473 | "source": [ 474 | "Timer('a,b = b,a', 'a=1; b=2').timeit()" 475 | ] 476 | }, 477 | { 478 | "cell_type": "markdown", 479 | "metadata": {}, 480 | "source": [ 481 | "## Tests, Templating, Multi-threading and Logging in Python #12" 482 | ] 483 | }, 484 | { 485 | "cell_type": "markdown", 486 | "metadata": {}, 487 | "source": [ 488 | "### Quality Control" 489 | ] 490 | }, 491 | { 492 | "cell_type": "code", 493 | "execution_count": null, 494 | "metadata": {}, 495 | "outputs": [], 496 | "source": [ 497 | "def average(values):\n", 498 | " \"\"\"Computes the arithmetic mean of a list of numbers.\n", 499 | "\n", 500 | " >>> print(average([20, 30, 70]))\n", 501 | " 40.0\n", 502 | " \"\"\"\n", 503 | " return sum(values) / len(values)\n", 504 | "\n", 505 | "import doctest\n", 506 | "doctest.testmod() # automatically validate the embedded tests" 507 | ] 508 | }, 509 | { 510 | "cell_type": "code", 511 | "execution_count": null, 512 | "metadata": {}, 513 | "outputs": [], 514 | "source": [ 515 | "import unittest\n", 516 | "\n", 517 | "class TestStatisticalFunctions(unittest.TestCase):\n", 518 | "\n", 519 | " def test_average(self):\n", 520 | " self.assertEqual(average([20, 30, 70]), 40.0)\n", 521 | " self.assertEqual(round(average([1, 5, 7]), 1), 4.3)\n", 522 | " with self.assertRaises(ZeroDivisionError):\n", 523 | " average([])\n", 524 | " with self.assertRaises(TypeError):\n", 525 | " average(20, 30, 70)" 526 | ] 527 | }, 528 | { 529 | "cell_type": "code", 530 | "execution_count": null, 531 | "metadata": {}, 532 | "outputs": [], 533 | "source": [ 534 | "suite = unittest.TestLoader().loadTestsFromTestCase(TestStatisticalFunctions)\n", 535 | "runner = unittest.TextTestRunner(verbosity=2)\n", 536 | "runner.run(suite)" 537 | ] 538 | }, 539 | { 540 | "cell_type": "markdown", 541 | "metadata": {}, 542 | "source": [ 543 | "### Output Formatting" 544 | ] 545 | }, 546 | { 547 | "cell_type": "code", 548 | "execution_count": null, 549 | "metadata": {}, 550 | "outputs": [], 551 | "source": [ 552 | "import reprlib\n", 553 | "\n", 554 | "reprlib.repr(set('supercalifragilisticexpialidocious'))" 555 | ] 556 | }, 557 | { 558 | "cell_type": "code", 559 | "execution_count": null, 560 | "metadata": {}, 561 | "outputs": [], 562 | "source": [ 563 | "import pprint\n", 564 | "\n", 565 | "t = {'name': 'Amin',\n", 566 | " 'middle_name': 'M.',\n", 567 | " 'last_name':'Boulouma',\n", 568 | " 'websites': {\n", 569 | " 'contact':'amine.boulouma.com',\n", 570 | " 'blog':'amboulouma.com',\n", 571 | " 'projects': {\n", 572 | " '3aransia':'3aransia.com',\n", 573 | " 'tldrlibrary':'tldrlibrary.com'\n", 574 | " }\n", 575 | " }}\n", 576 | "\n", 577 | "print(t)\n", 578 | "pprint.pprint(t)" 579 | ] 580 | }, 581 | { 582 | "cell_type": "code", 583 | "execution_count": null, 584 | "metadata": {}, 585 | "outputs": [], 586 | "source": [ 587 | "import textwrap\n", 588 | "\n", 589 | "doc = \"\"\"The wrap() method is just like fill() except that it returns\n", 590 | " a list of strings instead of one big string with newlines to separate\n", 591 | " the wrapped lines.\"\"\"\n", 592 | "\n", 593 | "print(textwrap.fill(doc, width=40))" 594 | ] 595 | }, 596 | { 597 | "cell_type": "markdown", 598 | "metadata": {}, 599 | "source": [ 600 | "### Templating" 601 | ] 602 | }, 603 | { 604 | "cell_type": "code", 605 | "execution_count": null, 606 | "metadata": {}, 607 | "outputs": [], 608 | "source": [ 609 | "from string import Template\n", 610 | "\n", 611 | "t = Template('${village}folk send $$10 to $cause.')\n", 612 | "t.substitute(village='Nottingham', cause='the ditch fund')" 613 | ] 614 | }, 615 | { 616 | "cell_type": "code", 617 | "execution_count": null, 618 | "metadata": { 619 | "scrolled": true 620 | }, 621 | "outputs": [], 622 | "source": [ 623 | "t = Template('Return the $item to $owner.')\n", 624 | "d = dict(item='unladen swallow')\n", 625 | "t.substitute(d)" 626 | ] 627 | }, 628 | { 629 | "cell_type": "code", 630 | "execution_count": null, 631 | "metadata": { 632 | "scrolled": true 633 | }, 634 | "outputs": [], 635 | "source": [ 636 | "t.safe_substitute(d)" 637 | ] 638 | }, 639 | { 640 | "cell_type": "code", 641 | "execution_count": null, 642 | "metadata": {}, 643 | "outputs": [], 644 | "source": [ 645 | "import time, os.path\n", 646 | "\n", 647 | "photofiles = ['img_1074.jpg', 'img_1076.jpg', 'img_1077.jpg']\n", 648 | "class BatchRename(Template):\n", 649 | " delimiter = '%'\n", 650 | "\n", 651 | "fmt = input('Enter rename style (%d-date %n-seqnum %f-format): ') # rename as Amin_%n%f" 652 | ] 653 | }, 654 | { 655 | "cell_type": "code", 656 | "execution_count": null, 657 | "metadata": {}, 658 | "outputs": [], 659 | "source": [ 660 | "t = BatchRename(fmt)\n", 661 | "date = time.strftime('%d%b%y')\n", 662 | "for i, filename in enumerate(photofiles):\n", 663 | " base, ext = os.path.splitext(filename)\n", 664 | " newname = t.substitute(d=date, n=i, f=ext)\n", 665 | " print('{0} --> {1}'.format(filename, newname))" 666 | ] 667 | }, 668 | { 669 | "cell_type": "markdown", 670 | "metadata": {}, 671 | "source": [ 672 | "### Multi-threading" 673 | ] 674 | }, 675 | { 676 | "cell_type": "code", 677 | "execution_count": null, 678 | "metadata": {}, 679 | "outputs": [], 680 | "source": [ 681 | "import threading, zipfile\n", 682 | "\n", 683 | "class AsyncZip(threading.Thread):\n", 684 | " def __init__(self, infile, outfile):\n", 685 | " threading.Thread.__init__(self)\n", 686 | " self.infile = infile\n", 687 | " self.outfile = outfile\n", 688 | "\n", 689 | " def run(self):\n", 690 | " f = zipfile.ZipFile(self.outfile, 'w', zipfile.ZIP_DEFLATED)\n", 691 | " f.write(self.infile)\n", 692 | " f.close()\n", 693 | " print('Finished background zip of:', self.infile)\n", 694 | "\n", 695 | "background = AsyncZip('myFile.txt', 'myarchive.zip')\n", 696 | "background.start()\n", 697 | "print('The main program continues to run in foreground.')\n", 698 | "\n", 699 | "background.join() # Wait for the background task to finish\n", 700 | "print('Main program waited until background was done.')" 701 | ] 702 | }, 703 | { 704 | "cell_type": "markdown", 705 | "metadata": {}, 706 | "source": [ 707 | "### Logging" 708 | ] 709 | }, 710 | { 711 | "cell_type": "code", 712 | "execution_count": null, 713 | "metadata": {}, 714 | "outputs": [], 715 | "source": [ 716 | "import logging\n", 717 | "logging.debug('Debugging information')\n", 718 | "logging.info('Informational message')\n", 719 | "logging.warning('Warning:config file %s not found', 'server.conf')\n", 720 | "logging.error('Error occurred')\n", 721 | "logging.critical('Critical error -- shutting down')" 722 | ] 723 | }, 724 | { 725 | "cell_type": "markdown", 726 | "metadata": {}, 727 | "source": [ 728 | "## More on Lists, Heaps and Decimal Precision in Python #13" 729 | ] 730 | }, 731 | { 732 | "cell_type": "markdown", 733 | "metadata": {}, 734 | "source": [ 735 | "### Tools for Working with Lists" 736 | ] 737 | }, 738 | { 739 | "cell_type": "code", 740 | "execution_count": null, 741 | "metadata": {}, 742 | "outputs": [], 743 | "source": [ 744 | "from array import array\n", 745 | "a = array('H', [4000, 10, 700, 22222])\n", 746 | "sum(a)" 747 | ] 748 | }, 749 | { 750 | "cell_type": "code", 751 | "execution_count": null, 752 | "metadata": {}, 753 | "outputs": [], 754 | "source": [ 755 | "a[1:3]" 756 | ] 757 | }, 758 | { 759 | "cell_type": "code", 760 | "execution_count": null, 761 | "metadata": {}, 762 | "outputs": [], 763 | "source": [ 764 | "import bisect\n", 765 | "\n", 766 | "scores = [(100, 'perl'), (200, 'tcl'), (400, 'lua'), (500, 'python')]\n", 767 | "bisect.insort(scores, (300, 'ruby'))\n", 768 | "scores" 769 | ] 770 | }, 771 | { 772 | "cell_type": "markdown", 773 | "metadata": {}, 774 | "source": [ 775 | "\"heap\"" 776 | ] 777 | }, 778 | { 779 | "cell_type": "code", 780 | "execution_count": null, 781 | "metadata": { 782 | "scrolled": true 783 | }, 784 | "outputs": [], 785 | "source": [ 786 | "from heapq import heapify, heappop, heappush\n", 787 | "\n", 788 | "data = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0]\n", 789 | "heapify(data) # rearrange the list into heap order\n", 790 | "heappush(data, -5) # add a new entry\n", 791 | "[heappop(data) for i in range(3)] # fetch the three smallest entries" 792 | ] 793 | }, 794 | { 795 | "cell_type": "markdown", 796 | "metadata": {}, 797 | "source": [ 798 | "### Decimal Floating Point Arithmetic" 799 | ] 800 | }, 801 | { 802 | "cell_type": "markdown", 803 | "metadata": {}, 804 | "source": [ 805 | "Uses: \n", 806 | "- financial applications and other uses which require exact decimal representation,\n", 807 | "- control over precision,\n", 808 | "- control over rounding to meet legal or regulatory requirements,\n", 809 | "- tracking of significant decimal places, or\n", 810 | "- applications where the user expects the results to match calculations done by hand." 811 | ] 812 | }, 813 | { 814 | "cell_type": "code", 815 | "execution_count": null, 816 | "metadata": {}, 817 | "outputs": [], 818 | "source": [ 819 | "from decimal import *\n", 820 | "round(Decimal('0.70') * Decimal('1.05'), 2)" 821 | ] 822 | }, 823 | { 824 | "cell_type": "code", 825 | "execution_count": null, 826 | "metadata": {}, 827 | "outputs": [], 828 | "source": [ 829 | "round(.70 * 1.05, 2)" 830 | ] 831 | }, 832 | { 833 | "cell_type": "code", 834 | "execution_count": null, 835 | "metadata": {}, 836 | "outputs": [], 837 | "source": [ 838 | "getcontext().prec = 36\n", 839 | "Decimal(1) / Decimal(7)" 840 | ] 841 | } 842 | ], 843 | "metadata": { 844 | "kernelspec": { 845 | "display_name": "Python 3", 846 | "language": "python", 847 | "name": "python3" 848 | }, 849 | "language_info": { 850 | "codemirror_mode": { 851 | "name": "ipython", 852 | "version": 3 853 | }, 854 | "file_extension": ".py", 855 | "mimetype": "text/x-python", 856 | "name": "python", 857 | "nbconvert_exporter": "python", 858 | "pygments_lexer": "ipython3", 859 | "version": "3.8.5" 860 | } 861 | }, 862 | "nbformat": 4, 863 | "nbformat_minor": 4 864 | } 865 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/Python Ultimate Tutorial #1-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# [Amin M. Boulouma Blog](https://amboulouma.com)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Python Ultimate Tutorial #1" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "> [Reminder] 🔔\n", 22 | "- Help the creator channel reach 20k subscribers. He will keep uploading quality content for you: [Amin M. Boulouma Channel](https://www.youtube.com/channel/UCOZbokHO727qeStxeYSKMUQ?sub_confirmation=1)\n", 23 | "- This tutorial is best understood following the video playlist: [Python Ultimate Tutorial [Official Documentation]](https://www.youtube.com/watch?v=vQqisFjAnsE&list=PLpMTHmi814W0nSToTOC0Q18kREOjcJspW&index=1)" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "Hosted by Amin M. Boulouma, contact and questions: [amine.boulouma.com](https://amine.boulouma.com)\n", 31 | "- Python tutorial made simple: https://youtu.be/vQqisFjAnsE\n", 32 | "- Source code: https://amboulouma.com/python-tutorial\n", 33 | "- Github: https://github.com/amboulouma/python-ultimate-tutorial" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "### Documentation" 41 | ] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "metadata": {}, 46 | "source": [ 47 | "- Python Documentation: https://docs.python.org/3/\n", 48 | "- PEP 8: https://www.python.org/dev/peps/pep-0008/\n", 49 | "- Google Style Guide: https://google.github.io/styleguide/pyguide.html\n" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": {}, 55 | "source": [ 56 | "### Installation" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": {}, 62 | "source": [ 63 | "- Installing Anaconda: https://docs.anaconda.com/anaconda/install/\n", 64 | "- Installing Jupyter: https://jupyter.org/install\n", 65 | "- Online Jupyter notebook from Google: https://colab.research.google.com/\n", 66 | "- Installing Python: https://www.python.org/downloads/" 67 | ] 68 | }, 69 | { 70 | "cell_type": "markdown", 71 | "metadata": {}, 72 | "source": [ 73 | "> Python 3.9" 74 | ] 75 | }, 76 | { 77 | "cell_type": "markdown", 78 | "metadata": {}, 79 | "source": [ 80 | "## Table of content" 81 | ] 82 | }, 83 | { 84 | "cell_type": "markdown", 85 | "metadata": {}, 86 | "source": [ 87 | "- [1. Setting up the environment with Jupyter Notebook](https://youtu.be/vQqisFjAnsE)\n", 88 | "\n", 89 | "- [2. A simple Introduction to Python](https://youtu.be/vQqisFjAnsE)\n", 90 | "\n", 91 | "- [3. Create a calculator with Python](https://youtu.be/vQqisFjAnsE)\n", 92 | " - [3.1. Numbers](https://youtu.be/vQqisFjAnsE)\n", 93 | " - [3.2. Strings](https://youtu.be/vQqisFjAnsE)\n", 94 | " - [3.3. Lists](https://youtu.be/vQqisFjAnsE)\n", 95 | " - [3.4. First Steps Towards Programming](https://youtu.be/vQqisFjAnsE)\n", 96 | "\n", 97 | "- [4. Control Flow Tools](https://youtu.be/vQqisFjAnsE)\n", 98 | " - [4.1. if Statements](https://youtu.be/vQqisFjAnsE)\n", 99 | " - [4.2. for Statements](https://youtu.be/vQqisFjAnsE)\n", 100 | " - [4.3. The range() Function](https://youtu.be/vQqisFjAnsE)\n", 101 | " - [4.4. break and continue Statements, and else Clauses on Loops](https://youtu.be/vQqisFjAnsE)\n", 102 | " - [4.5. pass Statements](https://youtu.be/vQqisFjAnsE)\n", 103 | " - [4.6. Defining Functions](https://youtu.be/vQqisFjAnsE)\n", 104 | " - [4.7. More on Defining Functions](https://youtu.be/vQqisFjAnsE)\n", 105 | " - [4.7.1. Default Argument Values](https://youtu.be/vQqisFjAnsE)\n", 106 | " - [4.7.2. Keyword Arguments](https://youtu.be/vQqisFjAnsE)\n", 107 | " - [4.7.3. Special parameters](https://youtu.be/vQqisFjAnsE)\n", 108 | " - [4.7.3.1. Positional-or-Keyword Arguments](https://youtu.be/vQqisFjAnsE)\n", 109 | " - [4.7.3.2. Positional-Only Parameters](https://youtu.be/vQqisFjAnsE)\n", 110 | " - [4.7.3.3. Keyword-Only Arguments](https://youtu.be/vQqisFjAnsE)\n", 111 | " - [4.7.3.4. Function Examples](https://youtu.be/vQqisFjAnsE)\n", 112 | " - [4.7.3.5. Recap](https://youtu.be/vQqisFjAnsE)\n", 113 | " - [4.7.4. Arbitrary Argument Lists](https://youtu.be/vQqisFjAnsE)\n", 114 | " - [4.7.5. Unpacking Argument Lists](https://youtu.be/vQqisFjAnsE)\n", 115 | " - [4.7.6. Lambda Expressions](https://youtu.be/vQqisFjAnsE)\n", 116 | " - [4.7.7. Documentation Strings](https://youtu.be/vQqisFjAnsE)\n", 117 | " - [4.7.8. Function Annotations](https://youtu.be/vQqisFjAnsE)\n", 118 | " - [4.8. Intermezzo: Coding Style](https://youtu.be/vQqisFjAnsE)\n", 119 | "\n", 120 | "- [5. Data Structures](https://youtu.be/vQqisFjAnsE)\n", 121 | " - [5.1. More on Lists](https://youtu.be/vQqisFjAnsE)\n", 122 | " - [5.1.1. Using Lists as Stacks](https://youtu.be/vQqisFjAnsE)\n", 123 | " - [5.1.2. Using Lists as Queues](https://youtu.be/vQqisFjAnsE)\n", 124 | " - [5.1.3. List Comprehensions](https://youtu.be/vQqisFjAnsE)\n", 125 | " - [5.1.4. Nested List Comprehensions](https://youtu.be/vQqisFjAnsE)\n", 126 | " - [5.2. The del statement](https://youtu.be/vQqisFjAnsE)\n", 127 | " - [5.3. Tuples and Sequences](https://youtu.be/vQqisFjAnsE)\n", 128 | " - [5.4. Sets](https://youtu.be/vQqisFjAnsE)\n", 129 | " - [5.5. Dictionaries](https://youtu.be/vQqisFjAnsE)\n", 130 | " - [5.6. Looping Techniques](https://youtu.be/vQqisFjAnsE)\n", 131 | " - [5.7. More on Conditions](https://youtu.be/vQqisFjAnsE)\n", 132 | " - [5.8. Comparing Sequences and Other Types](https://youtu.be/vQqisFjAnsE)\n", 133 | "\n", 134 | "- [6. Modules](https://youtu.be/vQqisFjAnsE)\n", 135 | " - [6.1. More on Modules](https://youtu.be/vQqisFjAnsE)\n", 136 | " - [6.1.1. Executing modules as scripts](https://youtu.be/vQqisFjAnsE)\n", 137 | " - [6.1.2. The Module Search Path](https://youtu.be/vQqisFjAnsE)\n", 138 | " - [6.1.3. “Compiled” Python files](https://youtu.be/vQqisFjAnsE)\n", 139 | " - [6.2. Standard Modules](https://youtu.be/vQqisFjAnsE)\n", 140 | " - [6.3. The dir() Function](https://youtu.be/vQqisFjAnsE)\n", 141 | " - [6.4. Packages](https://youtu.be/vQqisFjAnsE)\n", 142 | " - [6.4.1. Importing * From a Package](https://youtu.be/vQqisFjAnsE)\n", 143 | " - [6.4.2. Intra-package References](https://youtu.be/vQqisFjAnsE)\n", 144 | " - [6.4.3. Packages in Multiple Directories](https://youtu.be/vQqisFjAnsE)\n", 145 | "\n", 146 | "- [7. Input and Output](https://youtu.be/vQqisFjAnsE)\n", 147 | " - [7.1. Fancier Output Formatting](https://youtu.be/vQqisFjAnsE)\n", 148 | " - [7.1.1. Formatted String Literals](https://youtu.be/vQqisFjAnsE)\n", 149 | " - [7.1.2. The String format() Method](https://youtu.be/vQqisFjAnsE)\n", 150 | " - [7.1.3. Manual String Formatting](https://youtu.be/vQqisFjAnsE)\n", 151 | " - [7.1.4. Old string formatting](https://youtu.be/vQqisFjAnsE)\n", 152 | " - [7.2. Reading and Writing Files](https://youtu.be/vQqisFjAnsE)\n", 153 | " - [7.2.1. Methods of File Objects](https://youtu.be/vQqisFjAnsE)\n", 154 | " - [7.2.2. Saving structured data with json](https://youtu.be/vQqisFjAnsE)\n", 155 | "\n", 156 | "- [8. Errors and Exceptions](https://youtu.be/vQqisFjAnsE)\n", 157 | " - [8.1. Syntax Errors](https://youtu.be/vQqisFjAnsE)\n", 158 | " - [8.2. Exceptions](https://youtu.be/vQqisFjAnsE)\n", 159 | " - [8.3. Handling Exceptions](https://youtu.be/vQqisFjAnsE)\n", 160 | " - [8.4. Raising Exceptions](https://youtu.be/vQqisFjAnsE)\n", 161 | " - [8.5. Exception Chaining](https://youtu.be/vQqisFjAnsE)\n", 162 | " - [8.6. User-defined Exceptions](https://youtu.be/vQqisFjAnsE)\n", 163 | " - [8.7. Defining Clean-up Actions](https://youtu.be/vQqisFjAnsE)\n", 164 | " - [8.8. Predefined Clean-up Actions](https://youtu.be/vQqisFjAnsE)\n", 165 | "\n", 166 | "- [9. Classes](https://youtu.be/vQqisFjAnsE)\n", 167 | " - [9.1. A Word About Names and Objects](https://youtu.be/vQqisFjAnsE)\n", 168 | " - [9.2. Python Scopes and Namespaces](https://youtu.be/vQqisFjAnsE)\n", 169 | " - [9.2.1. Scopes and Namespaces Example](https://youtu.be/vQqisFjAnsE)\n", 170 | " - [9.3. A First Look at Classes](https://youtu.be/vQqisFjAnsE)\n", 171 | " - [9.3.1. Class Definition Syntax](https://youtu.be/vQqisFjAnsE)\n", 172 | " - [9.3.2. Class Objects](https://youtu.be/vQqisFjAnsE)\n", 173 | " - [9.3.3. Instance Objects](https://youtu.be/vQqisFjAnsE)\n", 174 | " - [9.3.4. Method Objects](https://youtu.be/vQqisFjAnsE)\n", 175 | " - [9.3.5. Class and Instance Variables](https://youtu.be/vQqisFjAnsE)\n", 176 | " - [9.4. Random Remarks](https://youtu.be/vQqisFjAnsE)\n", 177 | " - [9.5. Inheritance](https://youtu.be/vQqisFjAnsE)\n", 178 | " - [9.5.1. Multiple Inheritance](https://youtu.be/vQqisFjAnsE)\n", 179 | " - [9.6. Private Variables](https://youtu.be/vQqisFjAnsE)\n", 180 | " - [9.7. Odds and Ends](https://youtu.be/vQqisFjAnsE)\n", 181 | " - [9.8. Iterators](https://youtu.be/vQqisFjAnsE)\n", 182 | " - [9.9. Generators](https://youtu.be/vQqisFjAnsE)\n", 183 | " - [9.10. Generator Expressions](https://youtu.be/vQqisFjAnsE)\n", 184 | "\n", 185 | "- [10. Brief Tour of the Standard Library](https://youtu.be/vQqisFjAnsE)\n", 186 | " - [10.1. Operating System Interface](https://youtu.be/vQqisFjAnsE)\n", 187 | " - [10.2. File Wildcards](https://youtu.be/vQqisFjAnsE)\n", 188 | " - [10.3. Command Line Arguments](https://youtu.be/vQqisFjAnsE)\n", 189 | " - [10.4. Error Output Redirection and Program Termination](https://youtu.be/vQqisFjAnsE)\n", 190 | " - [10.5. String Pattern Matching](https://youtu.be/vQqisFjAnsE)\n", 191 | " - [10.6. Mathematics](https://youtu.be/vQqisFjAnsE)\n", 192 | " - [10.7. Internet Access](https://youtu.be/vQqisFjAnsE)\n", 193 | " - [10.8. Dates and Times](https://youtu.be/vQqisFjAnsE)\n", 194 | " - [10.9. Data Compression](https://youtu.be/vQqisFjAnsE)\n", 195 | " - [10.10. Performance Measurement](https://youtu.be/vQqisFjAnsE)\n", 196 | " - [10.11. Quality Control](https://youtu.be/vQqisFjAnsE)\n", 197 | " - [10.12. Batteries Included](https://youtu.be/vQqisFjAnsE)\n", 198 | "\n", 199 | "- [11. Brief Tour of the Standard Library — Part II](https://youtu.be/vQqisFjAnsE)\n", 200 | " - [11.1. Output Formatting](https://youtu.be/vQqisFjAnsE)\n", 201 | " - [11.2. Templating](https://youtu.be/vQqisFjAnsE)\n", 202 | " - [11.3. Working with Binary Data Record Layouts](https://youtu.be/vQqisFjAnsE)\n", 203 | " - [11.4. Multi-threading](https://youtu.be/vQqisFjAnsE)\n", 204 | " - [11.5. Logging](https://youtu.be/vQqisFjAnsE)\n", 205 | " - [11.6. Weak References](https://youtu.be/vQqisFjAnsE)\n", 206 | " - [11.7. Tools for Working with Lists](https://youtu.be/vQqisFjAnsE)\n", 207 | " - [11.8. Decimal Floating Point Arithmetic](https://youtu.be/vQqisFjAnsE)\n", 208 | "\n", 209 | "- [12. Virtual Environments and Packages](https://youtu.be/vQqisFjAnsE)\n", 210 | " - [12.1. Introduction](https://youtu.be/vQqisFjAnsE)\n", 211 | " - [12.2. Creating Virtual Environments](https://youtu.be/vQqisFjAnsE)\n", 212 | " - [12.3. Managing Packages with pip](https://youtu.be/vQqisFjAnsE)\n", 213 | "\n", 214 | "- [13. PEP 8 - Style Guide for Python code](https://youtu.be/vQqisFjAnsE)\n", 215 | "\n", 216 | " - [13.1. Introduction](https://youtu.be/vQqisFjAnsE)\n", 217 | "\n", 218 | " - [13.2. A Foolish Consistency is the Hobgoblin of Little Minds](https://youtu.be/vQqisFjAnsE)\n", 219 | "\n", 220 | " - [13.3. Code Lay-out](https://youtu.be/vQqisFjAnsE)\n", 221 | " - [13.3.1. Indentation](https://youtu.be/vQqisFjAnsE)\n", 222 | " - [13.3.2. Tabs or Spaces?](https://youtu.be/vQqisFjAnsE)\n", 223 | " - [13.3.3. Maximum Line Length](https://youtu.be/vQqisFjAnsE)\n", 224 | " - [13.3.4. Should a Line Break Before or After a Binary Operator?](https://youtu.be/vQqisFjAnsE)\n", 225 | " - [13.3.5. Blank Lines](https://youtu.be/vQqisFjAnsE)\n", 226 | " - [13.3.6. Source File Encoding](https://youtu.be/vQqisFjAnsE)\n", 227 | " - [13.3.7. Imports](https://youtu.be/vQqisFjAnsE)\n", 228 | " - [13.3.8. Module Level Dunder Names](https://youtu.be/vQqisFjAnsE)\n", 229 | "\n", 230 | " - [13.4. String Quotes](https://youtu.be/vQqisFjAnsE)\n", 231 | "\n", 232 | " - [13.5. Whitespace in Expressions and Statements](https://youtu.be/vQqisFjAnsE)\n", 233 | " - [13.5.1. Pet Peeves](https://youtu.be/vQqisFjAnsE)\n", 234 | " - [13.5.2. Other Recommendations](https://youtu.be/vQqisFjAnsE)\n", 235 | "\n", 236 | " - [13.6. When to Use Trailing Commas](https://youtu.be/vQqisFjAnsE)\n", 237 | "\n", 238 | " - [13.7. Comments](https://youtu.be/vQqisFjAnsE)\n", 239 | " - [13.7.1. Block Comments](https://youtu.be/vQqisFjAnsE)\n", 240 | " - [13.7.2. Inline Comments](https://youtu.be/vQqisFjAnsE)\n", 241 | " - [13.7.3. Documentation Strings](https://youtu.be/vQqisFjAnsE)\n", 242 | "\n", 243 | " - [13.8. Naming Conventions](https://youtu.be/vQqisFjAnsE)\n", 244 | " - [13.8.1. Overriding Principle](https://youtu.be/vQqisFjAnsE)\n", 245 | " - [13.8.2. Descriptive: Naming Styles](https://youtu.be/vQqisFjAnsE)\n", 246 | " - [13.8.3. Prescriptive: Naming Conventions](https://youtu.be/vQqisFjAnsE)\n", 247 | " - [13.8.3.1. Names to Avoid](https://youtu.be/vQqisFjAnsE)\n", 248 | " - [13.8.3.2. ASCII Compatibility](https://youtu.be/vQqisFjAnsE)\n", 249 | " - [13.8.3.3. Package and Module Names](https://youtu.be/vQqisFjAnsE)\n", 250 | " - [13.8.3.4. Class Names](https://youtu.be/vQqisFjAnsE)\n", 251 | " - [13.8.3.5. Type Variable Names](https://youtu.be/vQqisFjAnsE)\n", 252 | " - [13.8.3.6. Exception Names](https://youtu.be/vQqisFjAnsE)\n", 253 | " - [13.8.3.7. Global Variable Names](https://youtu.be/vQqisFjAnsE)\n", 254 | " - [13.8.3.8. Function and Variable Names](https://youtu.be/vQqisFjAnsE)\n", 255 | " - [13.8.3.9. Function and Method Arguments](https://youtu.be/vQqisFjAnsE)\n", 256 | " - [13.8.3.10. Method Names and Instance Variables](https://youtu.be/vQqisFjAnsE)\n", 257 | " - [13.8.3.11. Constants](https://youtu.be/vQqisFjAnsE)\n", 258 | " - [13.8.3.12. Designing for Inheritance](https://youtu.be/vQqisFjAnsE)\n", 259 | " - [13.8.4. Public and Internal Interfaces](https://youtu.be/vQqisFjAnsE)\n", 260 | "\n", 261 | " - [13.9. Programming Recommendations](https://youtu.be/vQqisFjAnsE)\n", 262 | " - [13.9.1. Function Annotations](https://youtu.be/vQqisFjAnsE)\n", 263 | " - [13.9.2. Variable Annotations](https://youtu.be/vQqisFjAnsE)\n", 264 | "\n", 265 | "- [14. [BONUS] Google Python Style Guide](https://youtu.be/vQqisFjAnsE)\n", 266 | "\n", 267 | " - [14.1. Background](https://youtu.be/vQqisFjAnsE)\n", 268 | "\n", 269 | " - [14.2. Python Language Rules](https://youtu.be/vQqisFjAnsE)\n", 270 | " - [14.2.1. Lint](https://youtu.be/vQqisFjAnsE)\n", 271 | " - [14.2.2. Imports](https://youtu.be/vQqisFjAnsE)\n", 272 | " - [14.2.3. Packages](https://youtu.be/vQqisFjAnsE)\n", 273 | " - [14.2.4. Exceptions](https://youtu.be/vQqisFjAnsE)\n", 274 | " - [14.2.5. Global variables](https://youtu.be/vQqisFjAnsE)\n", 275 | " - [14.2.6. Nested/Local/Inner Classes and Functions](https://youtu.be/vQqisFjAnsE)\n", 276 | " - [14.2.7. Comprehensions & Generator Expressions](https://youtu.be/vQqisFjAnsE)\n", 277 | " - [14.2.8. Default Iterators and Operators](https://youtu.be/vQqisFjAnsE)\n", 278 | " - [14.2.9. Generators](https://youtu.be/vQqisFjAnsE)\n", 279 | " - [14.2.10. Lambda Functions](https://youtu.be/vQqisFjAnsE)\n", 280 | " - [14.2.11. Conditional Expressions](https://youtu.be/vQqisFjAnsE)\n", 281 | " - [14.2.12. Default Argument Values](https://youtu.be/vQqisFjAnsE)\n", 282 | " - [14.2.13. Properties](https://youtu.be/vQqisFjAnsE)\n", 283 | " - [14.2.14. True/False Evaluations](https://youtu.be/vQqisFjAnsE)\n", 284 | " - [14.2.16. Lexical Scoping](https://youtu.be/vQqisFjAnsE)\n", 285 | " - [14.2.17. Function and Method Decorators](https://youtu.be/vQqisFjAnsE)\n", 286 | " - [14.2.18. Threading](https://youtu.be/vQqisFjAnsE)\n", 287 | " - [14.2.19. Power Features](https://youtu.be/vQqisFjAnsE)\n", 288 | " - [14.2.20. Modern Python: Python 3 and from \\_\\_future__ imports](https://youtu.be/vQqisFjAnsE)\n", 289 | " - [14.2.21. Type Annotated Code](https://youtu.be/vQqisFjAnsE)\n", 290 | "\n", 291 | " - [14.3. Python Style Rules](https://youtu.be/vQqisFjAnsE)\n", 292 | " - [14.3.1. Semicolons](https://youtu.be/vQqisFjAnsE)\n", 293 | " - [14.3.2. Line length](https://youtu.be/vQqisFjAnsE)\n", 294 | " - [14.3.3. Parentheses](https://youtu.be/vQqisFjAnsE)\n", 295 | " - [14.3.4. Indentation](https://youtu.be/vQqisFjAnsE)\n", 296 | " - [14.3.4.1. Trailing commas in sequences of items?](https://youtu.be/vQqisFjAnsE)\n", 297 | " - [14.3.5. Blank Lines](https://youtu.be/vQqisFjAnsE)\n", 298 | " - [14.3.6. Whitespace](https://youtu.be/vQqisFjAnsE)\n", 299 | " - [14.3.7. Shebang Line](https://youtu.be/vQqisFjAnsE)\n", 300 | " - [14.3.8. Comments and Docstrings](https://youtu.be/vQqisFjAnsE)\n", 301 | " - [14.3.8.1. Docstrings](https://youtu.be/vQqisFjAnsE)\n", 302 | " - [14.3.8.2. Modules](https://youtu.be/vQqisFjAnsE)\n", 303 | " - [14.3.8.3. Functions and Methods](https://youtu.be/vQqisFjAnsE)\n", 304 | " - [14.3.8.4. Classes](https://youtu.be/vQqisFjAnsE)\n", 305 | " - [14.3.8.5. Block and Inline Comments](https://youtu.be/vQqisFjAnsE)\n", 306 | " - [14.3.8.6. Punctuation, Spelling, and Grammar](https://youtu.be/vQqisFjAnsE)\n", 307 | " - [14.3.10. Strings](https://youtu.be/vQqisFjAnsE)\n", 308 | " - [14.3.10.1. Logging](https://youtu.be/vQqisFjAnsE)\n", 309 | " - [14.3.10.2. Error Messages](https://youtu.be/vQqisFjAnsE)\n", 310 | " - [14.3.11. Files and Sockets](https://youtu.be/vQqisFjAnsE)\n", 311 | " - [14.3.12. TODO Comments](https://youtu.be/vQqisFjAnsE)\n", 312 | " - [14.3.13. Imports formatting](https://youtu.be/vQqisFjAnsE)\n", 313 | " - [14.3.14. Statements](https://youtu.be/vQqisFjAnsE)\n", 314 | " - [14.3.15. Accessors](https://youtu.be/vQqisFjAnsE)\n", 315 | " - [14.3.16. Naming](https://youtu.be/vQqisFjAnsE)\n", 316 | " - [14.3.16.1. Names to Avoid](https://youtu.be/vQqisFjAnsE)\n", 317 | " - [14.3.16.2. Naming Conventions](https://youtu.be/vQqisFjAnsE)\n", 318 | " - [14.3.16.3. File Naming](https://youtu.be/vQqisFjAnsE)\n", 319 | " - [14.3.16.4. Guidelines derived from Guido’s Recommendations](https://youtu.be/vQqisFjAnsE)\n", 320 | " - [14.3.17. Main](https://youtu.be/vQqisFjAnsE)\n", 321 | " - [14.3.18. Function length](https://youtu.be/vQqisFjAnsE)\n", 322 | " - [14.3.19. Type Annotations](https://youtu.be/vQqisFjAnsE)\n", 323 | " - [14.3.19.1. General Rules](https://youtu.be/vQqisFjAnsE)\n", 324 | " - [14.3.19.2. Line Breaking](https://youtu.be/vQqisFjAnsE)\n", 325 | " - [14.3.19.3. Forward Declarations](https://youtu.be/vQqisFjAnsE)\n", 326 | " - [14.3.19.4. Default Values](https://youtu.be/vQqisFjAnsE)\n", 327 | " - [14.3.19.5. NoneType](https://youtu.be/vQqisFjAnsE)\n", 328 | " - [14.3.19.6. Type Aliases](https://youtu.be/vQqisFjAnsE)\n", 329 | " - [14.3.19.7. Ignoring Types](https://youtu.be/vQqisFjAnsE)\n", 330 | " - [14.3.19.8. Typing Variables](https://youtu.be/vQqisFjAnsE)\n", 331 | " - [14.3.19.9. Tuples vs Lists](https://youtu.be/vQqisFjAnsE)\n", 332 | " - [14.3.19.10. TypeVars](https://youtu.be/vQqisFjAnsE)\n", 333 | " - [14.3.19.11. String types](https://youtu.be/vQqisFjAnsE)\n", 334 | " - [14.3.19.12. Imports For Typing](https://youtu.be/vQqisFjAnsE)\n", 335 | " - [14.3.19.13. Conditional Imports](https://youtu.be/vQqisFjAnsE)\n", 336 | " - [14.3.19.14. Circular Dependencies](https://youtu.be/vQqisFjAnsE)\n", 337 | " - [14.3.19.15. Generics](https://youtu.be/vQqisFjAnsE)\n", 338 | " - [14.3.19.16. Build Dependencies](https://youtu.be/vQqisFjAnsE)\n", 339 | "\n", 340 | " - [14.4. Parting Words](https://youtu.be/vQqisFjAnsE)\n", 341 | "- [15. Python libraries](https://youtu.be/vQqisFjAnsE)\n", 342 | "- [16. Python integretions with other technologies](https://youtu.be/vQqisFjAnsE)\n", 343 | "- [17. Python Web technologies](https://youtu.be/vQqisFjAnsE)\n", 344 | "- [18. Python Machine Learning](https://youtu.be/vQqisFjAnsE)\n", 345 | "- [19. Python automation](https://youtu.be/vQqisFjAnsE)\n", 346 | "- [20. Python modules](https://youtu.be/vQqisFjAnsE)\n", 347 | "- [21. Python coding challenges](https://youtu.be/vQqisFjAnsE)" 348 | ] 349 | } 350 | ], 351 | "metadata": { 352 | "kernelspec": { 353 | "display_name": "Python 3", 354 | "language": "python", 355 | "name": "python3" 356 | }, 357 | "language_info": { 358 | "codemirror_mode": { 359 | "name": "ipython", 360 | "version": 3 361 | }, 362 | "file_extension": ".py", 363 | "mimetype": "text/x-python", 364 | "name": "python", 365 | "nbconvert_exporter": "python", 366 | "pygments_lexer": "ipython3", 367 | "version": "3.8.5" 368 | } 369 | }, 370 | "nbformat": 4, 371 | "nbformat_minor": 4 372 | } 373 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/Template in Python #1-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# [Amin M. Boulouma Blog](https://amboulouma.com)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Template in Python #1" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "> [Reminder] 🔔\n", 22 | "- Help the creator channel reach 20k subscribers. He will keep uploading quality content for you: [Amin M. Boulouma Channel](https://www.youtube.com/channel/UCOZbokHO727qeStxeYSKMUQ?sub_confirmation=1)\n", 23 | "- This tutorial is best understood following the video playlist: [Python Ultimate Tutorial [Official Documentation]](https://www.youtube.com/watch?v=vQqisFjAnsE&list=PLpMTHmi814W0nSToTOC0Q18kREOjcJspW&index=1)" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "Hosted by Amin M. Boulouma, contact and questions: [amine.boulouma.com](https://amine.boulouma.com)\n", 31 | "- Python tutorial made simple: https://youtu.be/vQqisFjAnsE\n", 32 | "- Source code: https://amboulouma.com/python-tutorial\n", 33 | "- Github: https://github.com/amboulouma/python-ultimate-tutorial" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "### Template" 41 | ] 42 | } 43 | ], 44 | "metadata": { 45 | "kernelspec": { 46 | "display_name": "Python 3", 47 | "language": "python", 48 | "name": "python3" 49 | }, 50 | "language_info": { 51 | "codemirror_mode": { 52 | "name": "ipython", 53 | "version": 3 54 | }, 55 | "file_extension": ".py", 56 | "mimetype": "text/x-python", 57 | "name": "python", 58 | "nbconvert_exporter": "python", 59 | "pygments_lexer": "ipython3", 60 | "version": "3.8.5" 61 | } 62 | }, 63 | "nbformat": 4, 64 | "nbformat_minor": 4 65 | } 66 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/Virtual Environments and Packages in Python #14-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# [Amin M. Boulouma Blog](https://amboulouma.com)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Virtual Environments and Packages in Python #14" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "> [Reminder] 🔔\n", 22 | "- Help the creator channel reach 20k subscribers. He will keep uploading quality content for you: [Amin M. Boulouma Channel](https://www.youtube.com/channel/UCOZbokHO727qeStxeYSKMUQ?sub_confirmation=1)\n", 23 | "- This tutorial is best understood following the video playlist: [Python Ultimate Tutorial [Official Documentation]](https://www.youtube.com/watch?v=vQqisFjAnsE&list=PLpMTHmi814W0nSToTOC0Q18kREOjcJspW&index=1)" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "Hosted by Amin M. Boulouma, contact and questions: [amine.boulouma.com](https://amine.boulouma.com)\n", 31 | "- Python tutorial made simple: https://youtu.be/vQqisFjAnsE\n", 32 | "- Source code: https://amboulouma.com/python-tutorial\n", 33 | "- Github: https://github.com/amboulouma/python-ultimate-tutorial" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "### Creating a Python Virtual Environment" 41 | ] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "metadata": {}, 46 | "source": [ 47 | "python3 -m venv tutorial-env" 48 | ] 49 | }, 50 | { 51 | "cell_type": "markdown", 52 | "metadata": {}, 53 | "source": [ 54 | "source tutorial-env/bin/activate" 55 | ] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "metadata": {}, 60 | "source": [ 61 | "### Managing Packages with pip" 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "metadata": {}, 67 | "source": [ 68 | "python -m pip install novas" 69 | ] 70 | }, 71 | { 72 | "cell_type": "markdown", 73 | "metadata": {}, 74 | "source": [ 75 | "python -m pip install requests==2.6.0" 76 | ] 77 | }, 78 | { 79 | "cell_type": "markdown", 80 | "metadata": {}, 81 | "source": [ 82 | "python -m pip install --upgrade requests" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "pip show requests" 90 | ] 91 | }, 92 | { 93 | "cell_type": "markdown", 94 | "metadata": {}, 95 | "source": [ 96 | "pip list" 97 | ] 98 | }, 99 | { 100 | "cell_type": "markdown", 101 | "metadata": {}, 102 | "source": [ 103 | "pip freeze > requirements.txt" 104 | ] 105 | }, 106 | { 107 | "cell_type": "markdown", 108 | "metadata": {}, 109 | "source": [ 110 | "cat requirements.txt" 111 | ] 112 | }, 113 | { 114 | "cell_type": "markdown", 115 | "metadata": {}, 116 | "source": [ 117 | "python -m pip install -r requirements.txt" 118 | ] 119 | } 120 | ], 121 | "metadata": { 122 | "kernelspec": { 123 | "display_name": "Python 3", 124 | "language": "python", 125 | "name": "python3" 126 | }, 127 | "language_info": { 128 | "codemirror_mode": { 129 | "name": "ipython", 130 | "version": 3 131 | }, 132 | "file_extension": ".py", 133 | "mimetype": "text/x-python", 134 | "name": "python", 135 | "nbconvert_exporter": "python", 136 | "pygments_lexer": "ipython3", 137 | "version": "3.8.5" 138 | } 139 | }, 140 | "nbformat": 4, 141 | "nbformat_minor": 4 142 | } 143 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/if, for and loop statements in Python #3-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# [Amin M. Boulouma Blog](https://amboulouma.com)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## if, for and loop statements in Python #3" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "> [Reminder] 🔔\n", 22 | "- Help the creator channel reach 20k subscribers. He will keep uploading quality content for you: [Amin M. Boulouma Channel](https://www.youtube.com/channel/UCOZbokHO727qeStxeYSKMUQ?sub_confirmation=1)\n", 23 | "- This tutorial is best understood following the video playlist: [Python Ultimate Tutorial [Official Documentation]](https://www.youtube.com/watch?v=vQqisFjAnsE&list=PLpMTHmi814W0nSToTOC0Q18kREOjcJspW&index=1)" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "Hosted by Amin M. Boulouma, contact and questions: [amine.boulouma.com](https://amine.boulouma.com)\n", 31 | "- Python tutorial made simple: https://youtu.be/vQqisFjAnsE\n", 32 | "- Source code: https://amboulouma.com/python-tutorial\n", 33 | "- Github: https://github.com/amboulouma/python-ultimate-tutorial" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "### if Statements" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 6, 46 | "metadata": {}, 47 | "outputs": [ 48 | { 49 | "name": "stdout", 50 | "output_type": "stream", 51 | "text": [ 52 | "Please enter an integer: 1\n" 53 | ] 54 | } 55 | ], 56 | "source": [ 57 | "x = int(input(\"Please enter an integer: \"))" 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": 7, 63 | "metadata": {}, 64 | "outputs": [ 65 | { 66 | "name": "stdout", 67 | "output_type": "stream", 68 | "text": [ 69 | "Single\n" 70 | ] 71 | } 72 | ], 73 | "source": [ 74 | "if x < 0:\n", 75 | " x = 0\n", 76 | " print('Negative changed to zero')\n", 77 | "elif x == 0: # if ... Else if ... Else\n", 78 | " print('Zero')\n", 79 | "elif x == 1:\n", 80 | " print('Single')\n", 81 | "else:\n", 82 | " print('More')" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "### for Statements" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": 8, 95 | "metadata": {}, 96 | "outputs": [ 97 | { 98 | "name": "stdout", 99 | "output_type": "stream", 100 | "text": [ 101 | "cat 3\n", 102 | "window 6\n", 103 | "defenestrate 12\n" 104 | ] 105 | } 106 | ], 107 | "source": [ 108 | "# Measure some strings:\n", 109 | "words = ['cat', 'window', 'defenestrate']\n", 110 | "for w in words:\n", 111 | " print(w, len(w))" 112 | ] 113 | }, 114 | { 115 | "cell_type": "markdown", 116 | "metadata": {}, 117 | "source": [ 118 | "### The range() Function" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": 9, 124 | "metadata": {}, 125 | "outputs": [ 126 | { 127 | "name": "stdout", 128 | "output_type": "stream", 129 | "text": [ 130 | "0\n", 131 | "1\n", 132 | "2\n", 133 | "3\n", 134 | "4\n" 135 | ] 136 | } 137 | ], 138 | "source": [ 139 | "for i in range(5):\n", 140 | " print(i)" 141 | ] 142 | }, 143 | { 144 | "cell_type": "code", 145 | "execution_count": 13, 146 | "metadata": {}, 147 | "outputs": [ 148 | { 149 | "name": "stdout", 150 | "output_type": "stream", 151 | "text": [ 152 | "0 Mary\n", 153 | "2 a\n", 154 | "4 lamb\n" 155 | ] 156 | } 157 | ], 158 | "source": [ 159 | "a = ['Mary', 'had', 'a', 'little', 'lamb'] # len(a) == 5 ==> range(5)\n", 160 | "for i in range(0, len(a), 2):\n", 161 | " print(i, a[i])" 162 | ] 163 | }, 164 | { 165 | "cell_type": "code", 166 | "execution_count": 15, 167 | "metadata": {}, 168 | "outputs": [ 169 | { 170 | "name": "stdout", 171 | "output_type": "stream", 172 | "text": [ 173 | "range(1, 10, 2)\n" 174 | ] 175 | } 176 | ], 177 | "source": [ 178 | "print(range(1, 10, 2)) #start, end, step" 179 | ] 180 | }, 181 | { 182 | "cell_type": "code", 183 | "execution_count": 16, 184 | "metadata": {}, 185 | "outputs": [ 186 | { 187 | "data": { 188 | "text/plain": [ 189 | "6" 190 | ] 191 | }, 192 | "execution_count": 16, 193 | "metadata": {}, 194 | "output_type": "execute_result" 195 | } 196 | ], 197 | "source": [ 198 | "sum(range(4)) # 0 + 1 + 2 + 3" 199 | ] 200 | }, 201 | { 202 | "cell_type": "code", 203 | "execution_count": 17, 204 | "metadata": {}, 205 | "outputs": [ 206 | { 207 | "data": { 208 | "text/plain": [ 209 | "[0, 1, 2, 3]" 210 | ] 211 | }, 212 | "execution_count": 17, 213 | "metadata": {}, 214 | "output_type": "execute_result" 215 | } 216 | ], 217 | "source": [ 218 | "list(range(4))" 219 | ] 220 | }, 221 | { 222 | "cell_type": "markdown", 223 | "metadata": {}, 224 | "source": [ 225 | "### break and continue Statements, and else Clauses on Loops" 226 | ] 227 | }, 228 | { 229 | "cell_type": "markdown", 230 | "metadata": {}, 231 | "source": [ 232 | "#### Prime number printing" 233 | ] 234 | }, 235 | { 236 | "cell_type": "code", 237 | "execution_count": 18, 238 | "metadata": {}, 239 | "outputs": [ 240 | { 241 | "name": "stdout", 242 | "output_type": "stream", 243 | "text": [ 244 | "2 is a prime number\n", 245 | "3 is a prime number\n", 246 | "4 equals 2 * 2\n", 247 | "5 is a prime number\n", 248 | "6 equals 2 * 3\n", 249 | "7 is a prime number\n", 250 | "8 equals 2 * 4\n", 251 | "9 equals 3 * 3\n" 252 | ] 253 | } 254 | ], 255 | "source": [ 256 | "for n in range(2, 10): # n: 2 ... 10\n", 257 | " for x in range(2, n): # x: 2 ... n\n", 258 | " if n % x == 0: # n = 5, x: 2 ... 5, n%x == 0 means that n is divisble by x\n", 259 | " print(n, 'equals', x, '*', n//x)\n", 260 | " break\n", 261 | " else:\n", 262 | " # loop fell through without finding a factor\n", 263 | " print(n, 'is a prime number')" 264 | ] 265 | }, 266 | { 267 | "cell_type": "code", 268 | "execution_count": 19, 269 | "metadata": {}, 270 | "outputs": [ 271 | { 272 | "name": "stdout", 273 | "output_type": "stream", 274 | "text": [ 275 | "Found an even number 2\n", 276 | "Found an odd number 3\n", 277 | "Found an even number 4\n", 278 | "Found an odd number 5\n", 279 | "Found an even number 6\n", 280 | "Found an odd number 7\n", 281 | "Found an even number 8\n", 282 | "Found an odd number 9\n" 283 | ] 284 | } 285 | ], 286 | "source": [ 287 | "for num in range(2, 10):\n", 288 | " if num % 2 == 0:\n", 289 | " print(\"Found an even number\", num)\n", 290 | " continue # go to the next iteration of the loop, continue executing the loop with the next iteration\n", 291 | " print(\"Found an odd number\", num)" 292 | ] 293 | }, 294 | { 295 | "cell_type": "markdown", 296 | "metadata": {}, 297 | "source": [ 298 | "### pass Statements" 299 | ] 300 | }, 301 | { 302 | "cell_type": "code", 303 | "execution_count": 20, 304 | "metadata": {}, 305 | "outputs": [ 306 | { 307 | "ename": "KeyboardInterrupt", 308 | "evalue": "", 309 | "output_type": "error", 310 | "traceback": [ 311 | "\u001b[0;31m-------------------------\u001b[0m", 312 | "\u001b[0;31mKeyboardInterrupt\u001b[0mTraceback (most recent call last)", 313 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mwhile\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mpass\u001b[0m \u001b[0;31m# Busy-wait for keyboard interrupt (Ctrl+C)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 314 | "\u001b[0;31mKeyboardInterrupt\u001b[0m: " 315 | ] 316 | } 317 | ], 318 | "source": [ 319 | "while True:\n", 320 | " pass # Busy-wait for keyboard interrupt (Ctrl+C)" 321 | ] 322 | }, 323 | { 324 | "cell_type": "code", 325 | "execution_count": 21, 326 | "metadata": {}, 327 | "outputs": [], 328 | "source": [ 329 | "class MyEmptyClass:\n", 330 | " pass" 331 | ] 332 | }, 333 | { 334 | "cell_type": "code", 335 | "execution_count": 22, 336 | "metadata": {}, 337 | "outputs": [], 338 | "source": [ 339 | "def initlog(*args):\n", 340 | " pass # Remember to implement this!" 341 | ] 342 | } 343 | ], 344 | "metadata": { 345 | "kernelspec": { 346 | "display_name": "Python 3", 347 | "language": "python", 348 | "name": "python3" 349 | }, 350 | "language_info": { 351 | "codemirror_mode": { 352 | "name": "ipython", 353 | "version": 3 354 | }, 355 | "file_extension": ".py", 356 | "mimetype": "text/x-python", 357 | "name": "python", 358 | "nbconvert_exporter": "python", 359 | "pygments_lexer": "ipython3", 360 | "version": "3.8.5" 361 | } 362 | }, 363 | "nbformat": 4, 364 | "nbformat_minor": 4 365 | } 366 | -------------------------------------------------------------------------------- /Input and Output in Python #7.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# [Amin M. Boulouma Blog](https://amboulouma.com)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Input and Output in Python #7" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "> [Reminder] 🔔\n", 22 | "- Help the creator channel reach 20k subscribers. He will keep uploading quality content for you: [Amin M. Boulouma Channel](https://www.youtube.com/channel/UCOZbokHO727qeStxeYSKMUQ?sub_confirmation=1)\n", 23 | "- This tutorial is best understood following the video playlist: [Python Ultimate Tutorial [Official Documentation]](https://www.youtube.com/watch?v=vQqisFjAnsE&list=PLpMTHmi814W0nSToTOC0Q18kREOjcJspW&index=1)\n" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "Hosted by Amin M. Boulouma, contact and questions: [amine.boulouma.com](https://amine.boulouma.com)\n", 31 | "- Python tutorial made simple: https://youtu.be/vQqisFjAnsE\n", 32 | "- Source code: https://amboulouma.com/python-tutorial\n", 33 | "- Github: https://github.com/amboulouma/python-ultimate-tutorial" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "### Output formatting" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 1, 46 | "metadata": {}, 47 | "outputs": [ 48 | { 49 | "data": { 50 | "text/plain": [ 51 | "'Results of the 2016 Referendum'" 52 | ] 53 | }, 54 | "execution_count": 1, 55 | "metadata": {}, 56 | "output_type": "execute_result" 57 | } 58 | ], 59 | "source": [ 60 | "year = 2016\n", 61 | "event = 'Referendum'\n", 62 | "f'Results of the {year} {event}'" 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": 3, 68 | "metadata": {}, 69 | "outputs": [ 70 | { 71 | "data": { 72 | "text/plain": [ 73 | "'42572654 YES votes 49.673%'" 74 | ] 75 | }, 76 | "execution_count": 3, 77 | "metadata": {}, 78 | "output_type": "execute_result" 79 | } 80 | ], 81 | "source": [ 82 | "yes_votes = 42_572_654\n", 83 | "no_votes = 43_132_495\n", 84 | "percentage = yes_votes / (yes_votes + no_votes)\n", 85 | "'{} YES votes {:2.3%}'.format(yes_votes, percentage)" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": 4, 91 | "metadata": {}, 92 | "outputs": [ 93 | { 94 | "data": { 95 | "text/plain": [ 96 | "'Hello, world.'" 97 | ] 98 | }, 99 | "execution_count": 4, 100 | "metadata": {}, 101 | "output_type": "execute_result" 102 | } 103 | ], 104 | "source": [ 105 | "s = 'Hello, world.'\n", 106 | "str(s)" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": 5, 112 | "metadata": {}, 113 | "outputs": [ 114 | { 115 | "data": { 116 | "text/plain": [ 117 | "\"'Hello, world.'\"" 118 | ] 119 | }, 120 | "execution_count": 5, 121 | "metadata": {}, 122 | "output_type": "execute_result" 123 | } 124 | ], 125 | "source": [ 126 | "repr(s)" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": 6, 132 | "metadata": {}, 133 | "outputs": [ 134 | { 135 | "data": { 136 | "text/plain": [ 137 | "'0.14285714285714285'" 138 | ] 139 | }, 140 | "execution_count": 6, 141 | "metadata": {}, 142 | "output_type": "execute_result" 143 | } 144 | ], 145 | "source": [ 146 | "str(1/7)" 147 | ] 148 | }, 149 | { 150 | "cell_type": "code", 151 | "execution_count": 7, 152 | "metadata": {}, 153 | "outputs": [ 154 | { 155 | "name": "stdout", 156 | "output_type": "stream", 157 | "text": [ 158 | "The value of x is 32.5, and y is 40000...\n" 159 | ] 160 | } 161 | ], 162 | "source": [ 163 | "x = 10 * 3.25\n", 164 | "y = 200 * 200\n", 165 | "s = 'The value of x is ' + str(x) + ', and y is ' + str(y) + '...'\n", 166 | "print(s)" 167 | ] 168 | }, 169 | { 170 | "cell_type": "code", 171 | "execution_count": 8, 172 | "metadata": {}, 173 | "outputs": [ 174 | { 175 | "name": "stdout", 176 | "output_type": "stream", 177 | "text": [ 178 | "hello, world\n", 179 | "\n", 180 | "'hello, world\\n'\n" 181 | ] 182 | } 183 | ], 184 | "source": [ 185 | "# The repr() of a string adds string quotes and backslashes:\n", 186 | "hello = 'hello, world\\n'\n", 187 | "hellos = repr(hello)\n", 188 | "print(hello)\n", 189 | "print(hellos)" 190 | ] 191 | }, 192 | { 193 | "cell_type": "code", 194 | "execution_count": 9, 195 | "metadata": {}, 196 | "outputs": [ 197 | { 198 | "data": { 199 | "text/plain": [ 200 | "\"(32.5, 40000, ('spam', 'eggs'))\"" 201 | ] 202 | }, 203 | "execution_count": 9, 204 | "metadata": {}, 205 | "output_type": "execute_result" 206 | } 207 | ], 208 | "source": [ 209 | "# The argument to repr() may be any Python object:\n", 210 | "repr((x, y, ('spam', 'eggs')))" 211 | ] 212 | }, 213 | { 214 | "cell_type": "markdown", 215 | "metadata": {}, 216 | "source": [ 217 | "### Formatted String Literals" 218 | ] 219 | }, 220 | { 221 | "cell_type": "code", 222 | "execution_count": 12, 223 | "metadata": {}, 224 | "outputs": [ 225 | { 226 | "name": "stdout", 227 | "output_type": "stream", 228 | "text": [ 229 | "The value of pi is approximately 3.14.\n" 230 | ] 231 | } 232 | ], 233 | "source": [ 234 | "import math\n", 235 | "print(f'The value of pi is approximately {math.pi:.2f}.')" 236 | ] 237 | }, 238 | { 239 | "cell_type": "code", 240 | "execution_count": 15, 241 | "metadata": {}, 242 | "outputs": [ 243 | { 244 | "name": "stdout", 245 | "output_type": "stream", 246 | "text": [ 247 | "Sjoerd ==> 4127\n", 248 | "Jack ==> 4098\n", 249 | "Dcab ==> 7678\n" 250 | ] 251 | } 252 | ], 253 | "source": [ 254 | "table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 7678}\n", 255 | "for name, phone in table.items():\n", 256 | " print(f'{name:6} ==> {phone:5d}')" 257 | ] 258 | }, 259 | { 260 | "cell_type": "code", 261 | "execution_count": 16, 262 | "metadata": {}, 263 | "outputs": [ 264 | { 265 | "name": "stdout", 266 | "output_type": "stream", 267 | "text": [ 268 | "My hovercraft is full of eels.\n" 269 | ] 270 | } 271 | ], 272 | "source": [ 273 | "animals = 'eels'\n", 274 | "print(f'My hovercraft is full of {animals}.')" 275 | ] 276 | }, 277 | { 278 | "cell_type": "code", 279 | "execution_count": 17, 280 | "metadata": { 281 | "scrolled": false 282 | }, 283 | "outputs": [ 284 | { 285 | "name": "stdout", 286 | "output_type": "stream", 287 | "text": [ 288 | "My hovercraft is full of 'eels'.\n" 289 | ] 290 | } 291 | ], 292 | "source": [ 293 | "print(f'My hovercraft is full of {animals!r}.')" 294 | ] 295 | }, 296 | { 297 | "cell_type": "code", 298 | "execution_count": 18, 299 | "metadata": {}, 300 | "outputs": [ 301 | { 302 | "name": "stdout", 303 | "output_type": "stream", 304 | "text": [ 305 | "My hovercraft is full of 'eels'.\n" 306 | ] 307 | } 308 | ], 309 | "source": [ 310 | "print('My hovercraft is full of ' + repr(animals) + '.')" 311 | ] 312 | }, 313 | { 314 | "cell_type": "markdown", 315 | "metadata": {}, 316 | "source": [ 317 | "### The String format() Method" 318 | ] 319 | }, 320 | { 321 | "cell_type": "code", 322 | "execution_count": 19, 323 | "metadata": {}, 324 | "outputs": [ 325 | { 326 | "name": "stdout", 327 | "output_type": "stream", 328 | "text": [ 329 | "We are the knights who say \"Ni!\"\n" 330 | ] 331 | } 332 | ], 333 | "source": [ 334 | "print('We are the {} who say \"{}!\"'.format('knights', 'Ni'))" 335 | ] 336 | }, 337 | { 338 | "cell_type": "code", 339 | "execution_count": 20, 340 | "metadata": {}, 341 | "outputs": [ 342 | { 343 | "name": "stdout", 344 | "output_type": "stream", 345 | "text": [ 346 | "spam and eggs\n" 347 | ] 348 | } 349 | ], 350 | "source": [ 351 | "print('{0} and {1}'.format('spam', 'eggs'))" 352 | ] 353 | }, 354 | { 355 | "cell_type": "code", 356 | "execution_count": 21, 357 | "metadata": {}, 358 | "outputs": [ 359 | { 360 | "name": "stdout", 361 | "output_type": "stream", 362 | "text": [ 363 | "eggs and spam\n" 364 | ] 365 | } 366 | ], 367 | "source": [ 368 | "print('{1} and {0}'.format('spam', 'eggs'))" 369 | ] 370 | }, 371 | { 372 | "cell_type": "code", 373 | "execution_count": 22, 374 | "metadata": {}, 375 | "outputs": [ 376 | { 377 | "name": "stdout", 378 | "output_type": "stream", 379 | "text": [ 380 | "This spam is absolutely horrible.\n" 381 | ] 382 | } 383 | ], 384 | "source": [ 385 | "print('This {food} is {adjective}.'.format(\n", 386 | " food='spam', adjective='absolutely horrible'))" 387 | ] 388 | }, 389 | { 390 | "cell_type": "code", 391 | "execution_count": 23, 392 | "metadata": {}, 393 | "outputs": [ 394 | { 395 | "name": "stdout", 396 | "output_type": "stream", 397 | "text": [ 398 | "The story of Bill, Manfred, and Georg.\n" 399 | ] 400 | } 401 | ], 402 | "source": [ 403 | "print('The story of {0}, {1}, and {other}.'.format('Bill', 'Manfred',\n", 404 | " other='Georg'))" 405 | ] 406 | }, 407 | { 408 | "cell_type": "code", 409 | "execution_count": 24, 410 | "metadata": {}, 411 | "outputs": [ 412 | { 413 | "name": "stdout", 414 | "output_type": "stream", 415 | "text": [ 416 | "Jack: 4098; Sjoerd: 4127; Dcab: 8637678\n" 417 | ] 418 | } 419 | ], 420 | "source": [ 421 | "table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 8637678}\n", 422 | "print('Jack: {Jack:d}; Sjoerd: {Sjoerd:d}; Dcab: {Dcab:d}'.format(**table))" 423 | ] 424 | }, 425 | { 426 | "cell_type": "code", 427 | "execution_count": 26, 428 | "metadata": {}, 429 | "outputs": [ 430 | { 431 | "name": "stdout", 432 | "output_type": "stream", 433 | "text": [ 434 | " 1 1 1 1 1 1\n", 435 | " 2 4 8 16 32 64\n", 436 | " 3 9 27 81 243 729\n", 437 | " 4 16 64 256 1024 4096\n", 438 | " 5 25 125 625 3125 15625\n", 439 | " 6 36 216 1296 7776 46656\n", 440 | " 7 49 343 2401 16807 117649\n", 441 | " 8 64 512 4096 32768 262144\n", 442 | " 9 81 729 6561 59049 531441\n", 443 | "10 100 1000 10000 100000 1000000\n" 444 | ] 445 | } 446 | ], 447 | "source": [ 448 | " for x in range(1, 11):\n", 449 | " print('{0:2d} {1:3d} {2:4d} {3:5d} {4:6d} {5:7d}'.format(x, x*x, x*x*x, x**4, x**5, x**6))" 450 | ] 451 | }, 452 | { 453 | "cell_type": "markdown", 454 | "metadata": {}, 455 | "source": [ 456 | "### Manual String Formatting" 457 | ] 458 | }, 459 | { 460 | "cell_type": "code", 461 | "execution_count": 30, 462 | "metadata": {}, 463 | "outputs": [ 464 | { 465 | "name": "stdout", 466 | "output_type": "stream", 467 | "text": [ 468 | " 1 1 1 1\n", 469 | " 2 4 8 16\n", 470 | " 3 9 27 81\n", 471 | " 4 16 64 256\n", 472 | " 5 25 125 625\n", 473 | " 6 36 216 1296\n", 474 | " 7 49 343 2401\n", 475 | " 8 64 512 4096\n", 476 | " 9 81 729 6561\n", 477 | "10 100 1000 10000\n" 478 | ] 479 | } 480 | ], 481 | "source": [ 482 | "for x in range(1, 11):\n", 483 | " print(repr(x).rjust(2), repr(x*x).rjust(3), end=' ')\n", 484 | " # Note use of 'end' on previous line\n", 485 | " print(repr(x*x*x).rjust(4), end = ' ')\n", 486 | " \n", 487 | " print(repr(x*x*x*x).rjust(5))" 488 | ] 489 | }, 490 | { 491 | "cell_type": "code", 492 | "execution_count": 32, 493 | "metadata": {}, 494 | "outputs": [ 495 | { 496 | "data": { 497 | "text/plain": [ 498 | "'0000000012'" 499 | ] 500 | }, 501 | "execution_count": 32, 502 | "metadata": {}, 503 | "output_type": "execute_result" 504 | } 505 | ], 506 | "source": [ 507 | "'12'.zfill(10)" 508 | ] 509 | }, 510 | { 511 | "cell_type": "code", 512 | "execution_count": 33, 513 | "metadata": {}, 514 | "outputs": [ 515 | { 516 | "data": { 517 | "text/plain": [ 518 | "'-003.14'" 519 | ] 520 | }, 521 | "execution_count": 33, 522 | "metadata": {}, 523 | "output_type": "execute_result" 524 | } 525 | ], 526 | "source": [ 527 | "'-3.14'.zfill(7)" 528 | ] 529 | }, 530 | { 531 | "cell_type": "code", 532 | "execution_count": 34, 533 | "metadata": {}, 534 | "outputs": [ 535 | { 536 | "data": { 537 | "text/plain": [ 538 | "'3.14159265359'" 539 | ] 540 | }, 541 | "execution_count": 34, 542 | "metadata": {}, 543 | "output_type": "execute_result" 544 | } 545 | ], 546 | "source": [ 547 | "'3.14159265359'.zfill(5)" 548 | ] 549 | }, 550 | { 551 | "cell_type": "markdown", 552 | "metadata": {}, 553 | "source": [ 554 | "### Old string formatting" 555 | ] 556 | }, 557 | { 558 | "cell_type": "code", 559 | "execution_count": 35, 560 | "metadata": {}, 561 | "outputs": [ 562 | { 563 | "name": "stdout", 564 | "output_type": "stream", 565 | "text": [ 566 | "The value of pi is approximately 3.142.\n" 567 | ] 568 | } 569 | ], 570 | "source": [ 571 | "import math\n", 572 | "print('The value of pi is approximately %5.3f.' % math.pi)" 573 | ] 574 | }, 575 | { 576 | "cell_type": "markdown", 577 | "metadata": {}, 578 | "source": [ 579 | "### Reading and Writing Files" 580 | ] 581 | }, 582 | { 583 | "cell_type": "code", 584 | "execution_count": 40, 585 | "metadata": {}, 586 | "outputs": [], 587 | "source": [ 588 | "f = open('workfile', 'w')" 589 | ] 590 | }, 591 | { 592 | "cell_type": "code", 593 | "execution_count": 43, 594 | "metadata": {}, 595 | "outputs": [], 596 | "source": [ 597 | "with open('workfile') as f:\n", 598 | " read_data = f.read()" 599 | ] 600 | }, 601 | { 602 | "cell_type": "code", 603 | "execution_count": 44, 604 | "metadata": {}, 605 | "outputs": [ 606 | { 607 | "data": { 608 | "text/plain": [ 609 | "True" 610 | ] 611 | }, 612 | "execution_count": 44, 613 | "metadata": {}, 614 | "output_type": "execute_result" 615 | } 616 | ], 617 | "source": [ 618 | "f.closed" 619 | ] 620 | }, 621 | { 622 | "cell_type": "code", 623 | "execution_count": 42, 624 | "metadata": {}, 625 | "outputs": [ 626 | { 627 | "ename": "ValueError", 628 | "evalue": "I/O operation on closed file.", 629 | "output_type": "error", 630 | "traceback": [ 631 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 632 | "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", 633 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclose\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 634 | "\u001b[0;31mValueError\u001b[0m: I/O operation on closed file." 635 | ] 636 | } 637 | ], 638 | "source": [ 639 | "f.close()\n", 640 | "f.read()" 641 | ] 642 | }, 643 | { 644 | "cell_type": "markdown", 645 | "metadata": {}, 646 | "source": [ 647 | "### Methods of File Objects" 648 | ] 649 | }, 650 | { 651 | "cell_type": "code", 652 | "execution_count": 45, 653 | "metadata": {}, 654 | "outputs": [], 655 | "source": [ 656 | "with open('workfile', 'w') as f:\n", 657 | " f.write('This is the first line of the file.\\n')\n", 658 | " f.write('This is the second line of the file.\\n')\n", 659 | " " 660 | ] 661 | }, 662 | { 663 | "cell_type": "code", 664 | "execution_count": 46, 665 | "metadata": {}, 666 | "outputs": [ 667 | { 668 | "name": "stdout", 669 | "output_type": "stream", 670 | "text": [ 671 | "f.read 1 This is the first line of the file.\n", 672 | "This is the second line of the file.\n", 673 | "\n", 674 | "f.read 2 \n" 675 | ] 676 | } 677 | ], 678 | "source": [ 679 | "with open('workfile') as f:\n", 680 | " print('f.read 1', f.read())\n", 681 | " print('f.read 2', f.read())\n" 682 | ] 683 | }, 684 | { 685 | "cell_type": "code", 686 | "execution_count": 49, 687 | "metadata": {}, 688 | "outputs": [ 689 | { 690 | "name": "stdout", 691 | "output_type": "stream", 692 | "text": [ 693 | "['This is the first line of the file.\\n', 'This is the second line of the file.\\n']\n", 694 | "f.readline 1 \n", 695 | "f.readline 2 \n" 696 | ] 697 | } 698 | ], 699 | "source": [ 700 | "with open('workfile') as f:\n", 701 | " print(f.readlines())\n", 702 | " print('f.readline 1', f.readline())\n", 703 | " print('f.readline 2', f.readline())" 704 | ] 705 | }, 706 | { 707 | "cell_type": "code", 708 | "execution_count": 54, 709 | "metadata": {}, 710 | "outputs": [ 711 | { 712 | "name": "stdout", 713 | "output_type": "stream", 714 | "text": [ 715 | "This is the first line of the file.\n", 716 | "This is the second line of the file.\n" 717 | ] 718 | } 719 | ], 720 | "source": [ 721 | "with open('workfile') as f:\n", 722 | " for line in f:\n", 723 | " print(line, end='')" 724 | ] 725 | }, 726 | { 727 | "cell_type": "code", 728 | "execution_count": 55, 729 | "metadata": {}, 730 | "outputs": [ 731 | { 732 | "name": "stdout", 733 | "output_type": "stream", 734 | "text": [ 735 | "18\n" 736 | ] 737 | } 738 | ], 739 | "source": [ 740 | "with open('workfile', 'w') as f:\n", 741 | " value = ('the answer', 42)\n", 742 | " s = str(value) # convert the tuple to string\n", 743 | " print(f.write(s)) # return the file current position" 744 | ] 745 | }, 746 | { 747 | "cell_type": "code", 748 | "execution_count": 57, 749 | "metadata": {}, 750 | "outputs": [ 751 | { 752 | "name": "stdout", 753 | "output_type": "stream", 754 | "text": [ 755 | "('the answer', 42)\n" 756 | ] 757 | } 758 | ], 759 | "source": [ 760 | "with open('workfile', 'r') as f:\n", 761 | " print(next(f))" 762 | ] 763 | }, 764 | { 765 | "cell_type": "markdown", 766 | "metadata": {}, 767 | "source": [ 768 | "### Saving structured data with json" 769 | ] 770 | }, 771 | { 772 | "cell_type": "code", 773 | "execution_count": 58, 774 | "metadata": {}, 775 | "outputs": [ 776 | { 777 | "data": { 778 | "text/plain": [ 779 | "'[1, \"simple\", \"list\"]'" 780 | ] 781 | }, 782 | "execution_count": 58, 783 | "metadata": {}, 784 | "output_type": "execute_result" 785 | } 786 | ], 787 | "source": [ 788 | "import json\n", 789 | "x = [1, 'simple', 'list']\n", 790 | "json.dumps(x)" 791 | ] 792 | }, 793 | { 794 | "cell_type": "code", 795 | "execution_count": 60, 796 | "metadata": {}, 797 | "outputs": [], 798 | "source": [ 799 | "with open('workfile', 'w') as f:\n", 800 | " json.dump(x, f)" 801 | ] 802 | }, 803 | { 804 | "cell_type": "code", 805 | "execution_count": 61, 806 | "metadata": {}, 807 | "outputs": [], 808 | "source": [ 809 | "with open('workfile', 'r') as f:\n", 810 | " x = json.load(f)" 811 | ] 812 | }, 813 | { 814 | "cell_type": "code", 815 | "execution_count": 62, 816 | "metadata": {}, 817 | "outputs": [ 818 | { 819 | "data": { 820 | "text/plain": [ 821 | "[1, 'simple', 'list']" 822 | ] 823 | }, 824 | "execution_count": 62, 825 | "metadata": {}, 826 | "output_type": "execute_result" 827 | } 828 | ], 829 | "source": [ 830 | "x" 831 | ] 832 | } 833 | ], 834 | "metadata": { 835 | "kernelspec": { 836 | "display_name": "Python 3", 837 | "language": "python", 838 | "name": "python3" 839 | }, 840 | "language_info": { 841 | "codemirror_mode": { 842 | "name": "ipython", 843 | "version": 3 844 | }, 845 | "file_extension": ".py", 846 | "mimetype": "text/x-python", 847 | "name": "python", 848 | "nbconvert_exporter": "python", 849 | "pygments_lexer": "ipython3", 850 | "version": "3.8.5" 851 | } 852 | }, 853 | "nbformat": 4, 854 | "nbformat_minor": 4 855 | } 856 | -------------------------------------------------------------------------------- /Python Modules #6/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aminblm/python-ultimate-tutorial/298b388926c426bdf3c09d816b91e60b7db1c391/Python Modules #6/.DS_Store -------------------------------------------------------------------------------- /Python Modules #6/.ipynb_checkpoints/Python Modules #6-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# [Amin M. Boulouma Blog](https://amboulouma.com)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Python Modules #6" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "> [Reminder] 🔔\n", 22 | "- Help the creator channel reach 20k subscribers. He will keep uploading quality content for you: [Amin M. Boulouma Channel](https://www.youtube.com/channel/UCOZbokHO727qeStxeYSKMUQ?sub_confirmation=1)\n", 23 | "- This tutorial is best understood following the video playlist: [Python Ultimate Tutorial [Official Documentation]](https://www.youtube.com/watch?v=vQqisFjAnsE&list=PLpMTHmi814W0nSToTOC0Q18kREOjcJspW&index=1)" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "Hosted by Amin M. Boulouma, contact and questions: [amine.boulouma.com](https://amine.boulouma.com)\n", 31 | "- Python tutorial made simple: https://youtu.be/vQqisFjAnsE\n", 32 | "- Source code: https://amboulouma.com/python-tutorial\n", 33 | "- Github: https://github.com/amboulouma/python-ultimate-tutorial" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "### Modules" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": null, 46 | "metadata": {}, 47 | "outputs": [], 48 | "source": [ 49 | "import fibo\n", 50 | "\n", 51 | "fibo.fib(1000)" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": null, 57 | "metadata": {}, 58 | "outputs": [], 59 | "source": [ 60 | "fibo.fib2(100)" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": null, 66 | "metadata": {}, 67 | "outputs": [], 68 | "source": [ 69 | "fibo.__name__" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": null, 75 | "metadata": {}, 76 | "outputs": [], 77 | "source": [ 78 | "from fibo import fib, fib2\n", 79 | "\n", 80 | "fib(500)\n", 81 | "fib2(500)" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": null, 87 | "metadata": {}, 88 | "outputs": [], 89 | "source": [ 90 | "from fibo import *\n", 91 | "\n", 92 | "fib(500)" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": null, 98 | "metadata": {}, 99 | "outputs": [], 100 | "source": [ 101 | "import fibo as fib\n", 102 | "\n", 103 | "fib.fib(500)\n", 104 | "fib.__name__" 105 | ] 106 | }, 107 | { 108 | "cell_type": "code", 109 | "execution_count": null, 110 | "metadata": {}, 111 | "outputs": [], 112 | "source": [ 113 | "from fibo import fib as fibonacci\n", 114 | "fibonacci(500)" 115 | ] 116 | }, 117 | { 118 | "cell_type": "code", 119 | "execution_count": null, 120 | "metadata": {}, 121 | "outputs": [], 122 | "source": [ 123 | "import fibo" 124 | ] 125 | }, 126 | { 127 | "cell_type": "markdown", 128 | "metadata": {}, 129 | "source": [ 130 | "### Standard Modules" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 1, 136 | "metadata": {}, 137 | "outputs": [ 138 | { 139 | "data": { 140 | "text/plain": [ 141 | "['__builtins__',\n", 142 | " '__cached__',\n", 143 | " '__doc__',\n", 144 | " '__file__',\n", 145 | " '__loader__',\n", 146 | " '__name__',\n", 147 | " '__package__',\n", 148 | " '__spec__',\n", 149 | " 'fib',\n", 150 | " 'fib2']" 151 | ] 152 | }, 153 | "execution_count": 1, 154 | "metadata": {}, 155 | "output_type": "execute_result" 156 | } 157 | ], 158 | "source": [ 159 | "import fibo, sys\n", 160 | "dir(fibo)" 161 | ] 162 | }, 163 | { 164 | "cell_type": "code", 165 | "execution_count": 2, 166 | "metadata": { 167 | "scrolled": true 168 | }, 169 | "outputs": [ 170 | { 171 | "data": { 172 | "text/plain": [ 173 | "['__breakpointhook__',\n", 174 | " '__displayhook__',\n", 175 | " '__doc__',\n", 176 | " '__excepthook__',\n", 177 | " '__interactivehook__',\n", 178 | " '__loader__',\n", 179 | " '__name__',\n", 180 | " '__package__',\n", 181 | " '__spec__',\n", 182 | " '__stderr__',\n", 183 | " '__stdin__',\n", 184 | " '__stdout__',\n", 185 | " '__unraisablehook__',\n", 186 | " '_base_executable',\n", 187 | " '_clear_type_cache',\n", 188 | " '_current_frames',\n", 189 | " '_debugmallocstats',\n", 190 | " '_framework',\n", 191 | " '_getframe',\n", 192 | " '_git',\n", 193 | " '_home',\n", 194 | " '_xoptions',\n", 195 | " 'abiflags',\n", 196 | " 'addaudithook',\n", 197 | " 'api_version',\n", 198 | " 'argv',\n", 199 | " 'audit',\n", 200 | " 'base_exec_prefix',\n", 201 | " 'base_prefix',\n", 202 | " 'breakpointhook',\n", 203 | " 'builtin_module_names',\n", 204 | " 'byteorder',\n", 205 | " 'call_tracing',\n", 206 | " 'callstats',\n", 207 | " 'copyright',\n", 208 | " 'displayhook',\n", 209 | " 'dont_write_bytecode',\n", 210 | " 'exc_info',\n", 211 | " 'excepthook',\n", 212 | " 'exec_prefix',\n", 213 | " 'executable',\n", 214 | " 'exit',\n", 215 | " 'flags',\n", 216 | " 'float_info',\n", 217 | " 'float_repr_style',\n", 218 | " 'get_asyncgen_hooks',\n", 219 | " 'get_coroutine_origin_tracking_depth',\n", 220 | " 'getallocatedblocks',\n", 221 | " 'getcheckinterval',\n", 222 | " 'getdefaultencoding',\n", 223 | " 'getdlopenflags',\n", 224 | " 'getfilesystemencodeerrors',\n", 225 | " 'getfilesystemencoding',\n", 226 | " 'getprofile',\n", 227 | " 'getrecursionlimit',\n", 228 | " 'getrefcount',\n", 229 | " 'getsizeof',\n", 230 | " 'getswitchinterval',\n", 231 | " 'gettrace',\n", 232 | " 'hash_info',\n", 233 | " 'hexversion',\n", 234 | " 'implementation',\n", 235 | " 'int_info',\n", 236 | " 'intern',\n", 237 | " 'is_finalizing',\n", 238 | " 'maxsize',\n", 239 | " 'maxunicode',\n", 240 | " 'meta_path',\n", 241 | " 'modules',\n", 242 | " 'path',\n", 243 | " 'path_hooks',\n", 244 | " 'path_importer_cache',\n", 245 | " 'platform',\n", 246 | " 'prefix',\n", 247 | " 'ps1',\n", 248 | " 'ps2',\n", 249 | " 'ps3',\n", 250 | " 'pycache_prefix',\n", 251 | " 'set_asyncgen_hooks',\n", 252 | " 'set_coroutine_origin_tracking_depth',\n", 253 | " 'setcheckinterval',\n", 254 | " 'setdlopenflags',\n", 255 | " 'setprofile',\n", 256 | " 'setrecursionlimit',\n", 257 | " 'setswitchinterval',\n", 258 | " 'settrace',\n", 259 | " 'stderr',\n", 260 | " 'stdin',\n", 261 | " 'stdout',\n", 262 | " 'thread_info',\n", 263 | " 'unraisablehook',\n", 264 | " 'version',\n", 265 | " 'version_info',\n", 266 | " 'warnoptions']" 267 | ] 268 | }, 269 | "execution_count": 2, 270 | "metadata": {}, 271 | "output_type": "execute_result" 272 | } 273 | ], 274 | "source": [ 275 | "dir(sys)" 276 | ] 277 | }, 278 | { 279 | "cell_type": "code", 280 | "execution_count": 3, 281 | "metadata": {}, 282 | "outputs": [ 283 | { 284 | "data": { 285 | "text/plain": [ 286 | "['In',\n", 287 | " 'Out',\n", 288 | " '_',\n", 289 | " '_1',\n", 290 | " '_2',\n", 291 | " '__',\n", 292 | " '___',\n", 293 | " '__builtin__',\n", 294 | " '__builtins__',\n", 295 | " '__doc__',\n", 296 | " '__loader__',\n", 297 | " '__name__',\n", 298 | " '__package__',\n", 299 | " '__spec__',\n", 300 | " '_dh',\n", 301 | " '_i',\n", 302 | " '_i1',\n", 303 | " '_i2',\n", 304 | " '_i3',\n", 305 | " '_ih',\n", 306 | " '_ii',\n", 307 | " '_iii',\n", 308 | " '_oh',\n", 309 | " 'a',\n", 310 | " 'exit',\n", 311 | " 'fibo',\n", 312 | " 'get_ipython',\n", 313 | " 'quit',\n", 314 | " 'sys']" 315 | ] 316 | }, 317 | "execution_count": 3, 318 | "metadata": {}, 319 | "output_type": "execute_result" 320 | } 321 | ], 322 | "source": [ 323 | "a = [1, 2, 3, 4, 5]\n", 324 | "dir()" 325 | ] 326 | }, 327 | { 328 | "cell_type": "code", 329 | "execution_count": 4, 330 | "metadata": {}, 331 | "outputs": [ 332 | { 333 | "data": { 334 | "text/plain": [ 335 | "['ArithmeticError',\n", 336 | " 'AssertionError',\n", 337 | " 'AttributeError',\n", 338 | " 'BaseException',\n", 339 | " 'BlockingIOError',\n", 340 | " 'BrokenPipeError',\n", 341 | " 'BufferError',\n", 342 | " 'BytesWarning',\n", 343 | " 'ChildProcessError',\n", 344 | " 'ConnectionAbortedError',\n", 345 | " 'ConnectionError',\n", 346 | " 'ConnectionRefusedError',\n", 347 | " 'ConnectionResetError',\n", 348 | " 'DeprecationWarning',\n", 349 | " 'EOFError',\n", 350 | " 'Ellipsis',\n", 351 | " 'EnvironmentError',\n", 352 | " 'Exception',\n", 353 | " 'False',\n", 354 | " 'FileExistsError',\n", 355 | " 'FileNotFoundError',\n", 356 | " 'FloatingPointError',\n", 357 | " 'FutureWarning',\n", 358 | " 'GeneratorExit',\n", 359 | " 'IOError',\n", 360 | " 'ImportError',\n", 361 | " 'ImportWarning',\n", 362 | " 'IndentationError',\n", 363 | " 'IndexError',\n", 364 | " 'InterruptedError',\n", 365 | " 'IsADirectoryError',\n", 366 | " 'KeyError',\n", 367 | " 'KeyboardInterrupt',\n", 368 | " 'LookupError',\n", 369 | " 'MemoryError',\n", 370 | " 'ModuleNotFoundError',\n", 371 | " 'NameError',\n", 372 | " 'None',\n", 373 | " 'NotADirectoryError',\n", 374 | " 'NotImplemented',\n", 375 | " 'NotImplementedError',\n", 376 | " 'OSError',\n", 377 | " 'OverflowError',\n", 378 | " 'PendingDeprecationWarning',\n", 379 | " 'PermissionError',\n", 380 | " 'ProcessLookupError',\n", 381 | " 'RecursionError',\n", 382 | " 'ReferenceError',\n", 383 | " 'ResourceWarning',\n", 384 | " 'RuntimeError',\n", 385 | " 'RuntimeWarning',\n", 386 | " 'StopAsyncIteration',\n", 387 | " 'StopIteration',\n", 388 | " 'SyntaxError',\n", 389 | " 'SyntaxWarning',\n", 390 | " 'SystemError',\n", 391 | " 'SystemExit',\n", 392 | " 'TabError',\n", 393 | " 'TimeoutError',\n", 394 | " 'True',\n", 395 | " 'TypeError',\n", 396 | " 'UnboundLocalError',\n", 397 | " 'UnicodeDecodeError',\n", 398 | " 'UnicodeEncodeError',\n", 399 | " 'UnicodeError',\n", 400 | " 'UnicodeTranslateError',\n", 401 | " 'UnicodeWarning',\n", 402 | " 'UserWarning',\n", 403 | " 'ValueError',\n", 404 | " 'Warning',\n", 405 | " 'ZeroDivisionError',\n", 406 | " '__IPYTHON__',\n", 407 | " '__build_class__',\n", 408 | " '__debug__',\n", 409 | " '__doc__',\n", 410 | " '__import__',\n", 411 | " '__loader__',\n", 412 | " '__name__',\n", 413 | " '__package__',\n", 414 | " '__spec__',\n", 415 | " 'abs',\n", 416 | " 'all',\n", 417 | " 'any',\n", 418 | " 'ascii',\n", 419 | " 'bin',\n", 420 | " 'bool',\n", 421 | " 'breakpoint',\n", 422 | " 'bytearray',\n", 423 | " 'bytes',\n", 424 | " 'callable',\n", 425 | " 'chr',\n", 426 | " 'classmethod',\n", 427 | " 'compile',\n", 428 | " 'complex',\n", 429 | " 'copyright',\n", 430 | " 'credits',\n", 431 | " 'delattr',\n", 432 | " 'dict',\n", 433 | " 'dir',\n", 434 | " 'display',\n", 435 | " 'divmod',\n", 436 | " 'enumerate',\n", 437 | " 'eval',\n", 438 | " 'exec',\n", 439 | " 'filter',\n", 440 | " 'float',\n", 441 | " 'format',\n", 442 | " 'frozenset',\n", 443 | " 'get_ipython',\n", 444 | " 'getattr',\n", 445 | " 'globals',\n", 446 | " 'hasattr',\n", 447 | " 'hash',\n", 448 | " 'help',\n", 449 | " 'hex',\n", 450 | " 'id',\n", 451 | " 'input',\n", 452 | " 'int',\n", 453 | " 'isinstance',\n", 454 | " 'issubclass',\n", 455 | " 'iter',\n", 456 | " 'len',\n", 457 | " 'license',\n", 458 | " 'list',\n", 459 | " 'locals',\n", 460 | " 'map',\n", 461 | " 'max',\n", 462 | " 'memoryview',\n", 463 | " 'min',\n", 464 | " 'next',\n", 465 | " 'object',\n", 466 | " 'oct',\n", 467 | " 'open',\n", 468 | " 'ord',\n", 469 | " 'pow',\n", 470 | " 'print',\n", 471 | " 'property',\n", 472 | " 'range',\n", 473 | " 'repr',\n", 474 | " 'reversed',\n", 475 | " 'round',\n", 476 | " 'set',\n", 477 | " 'setattr',\n", 478 | " 'slice',\n", 479 | " 'sorted',\n", 480 | " 'staticmethod',\n", 481 | " 'str',\n", 482 | " 'sum',\n", 483 | " 'super',\n", 484 | " 'tuple',\n", 485 | " 'type',\n", 486 | " 'vars',\n", 487 | " 'zip']" 488 | ] 489 | }, 490 | "execution_count": 4, 491 | "metadata": {}, 492 | "output_type": "execute_result" 493 | } 494 | ], 495 | "source": [ 496 | "import builtins\n", 497 | "dir(builtins) " 498 | ] 499 | }, 500 | { 501 | "cell_type": "code", 502 | "execution_count": 5, 503 | "metadata": {}, 504 | "outputs": [ 505 | { 506 | "data": { 507 | "text/plain": [ 508 | "153" 509 | ] 510 | }, 511 | "execution_count": 5, 512 | "metadata": {}, 513 | "output_type": "execute_result" 514 | } 515 | ], 516 | "source": [ 517 | "len(dir(builtins))" 518 | ] 519 | }, 520 | { 521 | "cell_type": "markdown", 522 | "metadata": {}, 523 | "source": [ 524 | "### Packages" 525 | ] 526 | }, 527 | { 528 | "cell_type": "raw", 529 | "metadata": {}, 530 | "source": [ 531 | "sound/ Top-level package\n", 532 | " __init__.py Initialize the sound package\n", 533 | " formats/ Subpackage for file format conversions\n", 534 | " __init__.py\n", 535 | " wavread.py\n", 536 | " wavwrite.py\n", 537 | " aiffread.py\n", 538 | " aiffwrite.py\n", 539 | " auread.py\n", 540 | " auwrite.py\n", 541 | " ...\n", 542 | " effects/ Subpackage for sound effects\n", 543 | " __init__.py\n", 544 | " echo.py\n", 545 | " surround.py\n", 546 | " reverse.py\n", 547 | " ...\n", 548 | " filters/ Subpackage for filters\n", 549 | " __init__.py\n", 550 | " equalizer.py\n", 551 | " vocoder.py\n", 552 | " karaoke.py\n", 553 | " ..." 554 | ] 555 | }, 556 | { 557 | "cell_type": "code", 558 | "execution_count": null, 559 | "metadata": {}, 560 | "outputs": [], 561 | "source": [ 562 | "import sound.effects.echo\n", 563 | "sound.effects.echo.echofilter(input, output, delay=0.7, atten=4)" 564 | ] 565 | }, 566 | { 567 | "cell_type": "code", 568 | "execution_count": null, 569 | "metadata": {}, 570 | "outputs": [], 571 | "source": [ 572 | "from sound.effects import echo\n", 573 | "echo.echofilter(input, output, delay=0.7, atten=4)" 574 | ] 575 | }, 576 | { 577 | "cell_type": "code", 578 | "execution_count": null, 579 | "metadata": {}, 580 | "outputs": [], 581 | "source": [ 582 | "from sound.effects.echo import echofilter\n", 583 | "echofilter(input, output, delay=0.7, atten=4)" 584 | ] 585 | }, 586 | { 587 | "cell_type": "markdown", 588 | "metadata": {}, 589 | "source": [ 590 | "### Intra-package References" 591 | ] 592 | }, 593 | { 594 | "cell_type": "code", 595 | "execution_count": null, 596 | "metadata": {}, 597 | "outputs": [], 598 | "source": [ 599 | "from . import echo\n", 600 | "from .. import formats\n", 601 | "from ..filters import equalizer" 602 | ] 603 | } 604 | ], 605 | "metadata": { 606 | "kernelspec": { 607 | "display_name": "Python 3", 608 | "language": "python", 609 | "name": "python3" 610 | }, 611 | "language_info": { 612 | "codemirror_mode": { 613 | "name": "ipython", 614 | "version": 3 615 | }, 616 | "file_extension": ".py", 617 | "mimetype": "text/x-python", 618 | "name": "python", 619 | "nbconvert_exporter": "python", 620 | "pygments_lexer": "ipython3", 621 | "version": "3.8.5" 622 | } 623 | }, 624 | "nbformat": 4, 625 | "nbformat_minor": 4 626 | } 627 | -------------------------------------------------------------------------------- /Python Modules #6/Python Modules #6.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# [Amin M. Boulouma Blog](https://amboulouma.com)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Python Modules #6" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "> [Reminder] 🔔\n", 22 | "- Help the creator channel reach 20k subscribers. He will keep uploading quality content for you: [Amin M. Boulouma Channel](https://www.youtube.com/channel/UCOZbokHO727qeStxeYSKMUQ?sub_confirmation=1)\n", 23 | "- This tutorial is best understood following the video playlist: [Python Ultimate Tutorial [Official Documentation]](https://www.youtube.com/watch?v=vQqisFjAnsE&list=PLpMTHmi814W0nSToTOC0Q18kREOjcJspW&index=1)" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "Hosted by Amin M. Boulouma, contact and questions: [amine.boulouma.com](https://amine.boulouma.com)\n", 31 | "- Python tutorial made simple: https://youtu.be/vQqisFjAnsE\n", 32 | "- Source code: https://amboulouma.com/python-tutorial\n", 33 | "- Github: https://github.com/amboulouma/python-ultimate-tutorial" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "### Modules" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": null, 46 | "metadata": {}, 47 | "outputs": [], 48 | "source": [ 49 | "import fibo\n", 50 | "\n", 51 | "fibo.fib(1000)" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": null, 57 | "metadata": {}, 58 | "outputs": [], 59 | "source": [ 60 | "fibo.fib2(100)" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": null, 66 | "metadata": {}, 67 | "outputs": [], 68 | "source": [ 69 | "fibo.__name__" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": null, 75 | "metadata": {}, 76 | "outputs": [], 77 | "source": [ 78 | "from fibo import fib, fib2\n", 79 | "\n", 80 | "fib(500)\n", 81 | "fib2(500)" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": null, 87 | "metadata": {}, 88 | "outputs": [], 89 | "source": [ 90 | "from fibo import *\n", 91 | "\n", 92 | "fib(500)" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": null, 98 | "metadata": {}, 99 | "outputs": [], 100 | "source": [ 101 | "import fibo as fib\n", 102 | "\n", 103 | "fib.fib(500)\n", 104 | "fib.__name__" 105 | ] 106 | }, 107 | { 108 | "cell_type": "code", 109 | "execution_count": null, 110 | "metadata": {}, 111 | "outputs": [], 112 | "source": [ 113 | "from fibo import fib as fibonacci\n", 114 | "fibonacci(500)" 115 | ] 116 | }, 117 | { 118 | "cell_type": "code", 119 | "execution_count": null, 120 | "metadata": {}, 121 | "outputs": [], 122 | "source": [ 123 | "import fibo" 124 | ] 125 | }, 126 | { 127 | "cell_type": "markdown", 128 | "metadata": {}, 129 | "source": [ 130 | "### Standard Modules" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 1, 136 | "metadata": {}, 137 | "outputs": [ 138 | { 139 | "data": { 140 | "text/plain": [ 141 | "['__builtins__',\n", 142 | " '__cached__',\n", 143 | " '__doc__',\n", 144 | " '__file__',\n", 145 | " '__loader__',\n", 146 | " '__name__',\n", 147 | " '__package__',\n", 148 | " '__spec__',\n", 149 | " 'fib',\n", 150 | " 'fib2']" 151 | ] 152 | }, 153 | "execution_count": 1, 154 | "metadata": {}, 155 | "output_type": "execute_result" 156 | } 157 | ], 158 | "source": [ 159 | "import fibo, sys\n", 160 | "dir(fibo)" 161 | ] 162 | }, 163 | { 164 | "cell_type": "code", 165 | "execution_count": 2, 166 | "metadata": { 167 | "scrolled": true 168 | }, 169 | "outputs": [ 170 | { 171 | "data": { 172 | "text/plain": [ 173 | "['__breakpointhook__',\n", 174 | " '__displayhook__',\n", 175 | " '__doc__',\n", 176 | " '__excepthook__',\n", 177 | " '__interactivehook__',\n", 178 | " '__loader__',\n", 179 | " '__name__',\n", 180 | " '__package__',\n", 181 | " '__spec__',\n", 182 | " '__stderr__',\n", 183 | " '__stdin__',\n", 184 | " '__stdout__',\n", 185 | " '__unraisablehook__',\n", 186 | " '_base_executable',\n", 187 | " '_clear_type_cache',\n", 188 | " '_current_frames',\n", 189 | " '_debugmallocstats',\n", 190 | " '_framework',\n", 191 | " '_getframe',\n", 192 | " '_git',\n", 193 | " '_home',\n", 194 | " '_xoptions',\n", 195 | " 'abiflags',\n", 196 | " 'addaudithook',\n", 197 | " 'api_version',\n", 198 | " 'argv',\n", 199 | " 'audit',\n", 200 | " 'base_exec_prefix',\n", 201 | " 'base_prefix',\n", 202 | " 'breakpointhook',\n", 203 | " 'builtin_module_names',\n", 204 | " 'byteorder',\n", 205 | " 'call_tracing',\n", 206 | " 'callstats',\n", 207 | " 'copyright',\n", 208 | " 'displayhook',\n", 209 | " 'dont_write_bytecode',\n", 210 | " 'exc_info',\n", 211 | " 'excepthook',\n", 212 | " 'exec_prefix',\n", 213 | " 'executable',\n", 214 | " 'exit',\n", 215 | " 'flags',\n", 216 | " 'float_info',\n", 217 | " 'float_repr_style',\n", 218 | " 'get_asyncgen_hooks',\n", 219 | " 'get_coroutine_origin_tracking_depth',\n", 220 | " 'getallocatedblocks',\n", 221 | " 'getcheckinterval',\n", 222 | " 'getdefaultencoding',\n", 223 | " 'getdlopenflags',\n", 224 | " 'getfilesystemencodeerrors',\n", 225 | " 'getfilesystemencoding',\n", 226 | " 'getprofile',\n", 227 | " 'getrecursionlimit',\n", 228 | " 'getrefcount',\n", 229 | " 'getsizeof',\n", 230 | " 'getswitchinterval',\n", 231 | " 'gettrace',\n", 232 | " 'hash_info',\n", 233 | " 'hexversion',\n", 234 | " 'implementation',\n", 235 | " 'int_info',\n", 236 | " 'intern',\n", 237 | " 'is_finalizing',\n", 238 | " 'maxsize',\n", 239 | " 'maxunicode',\n", 240 | " 'meta_path',\n", 241 | " 'modules',\n", 242 | " 'path',\n", 243 | " 'path_hooks',\n", 244 | " 'path_importer_cache',\n", 245 | " 'platform',\n", 246 | " 'prefix',\n", 247 | " 'ps1',\n", 248 | " 'ps2',\n", 249 | " 'ps3',\n", 250 | " 'pycache_prefix',\n", 251 | " 'set_asyncgen_hooks',\n", 252 | " 'set_coroutine_origin_tracking_depth',\n", 253 | " 'setcheckinterval',\n", 254 | " 'setdlopenflags',\n", 255 | " 'setprofile',\n", 256 | " 'setrecursionlimit',\n", 257 | " 'setswitchinterval',\n", 258 | " 'settrace',\n", 259 | " 'stderr',\n", 260 | " 'stdin',\n", 261 | " 'stdout',\n", 262 | " 'thread_info',\n", 263 | " 'unraisablehook',\n", 264 | " 'version',\n", 265 | " 'version_info',\n", 266 | " 'warnoptions']" 267 | ] 268 | }, 269 | "execution_count": 2, 270 | "metadata": {}, 271 | "output_type": "execute_result" 272 | } 273 | ], 274 | "source": [ 275 | "dir(sys)" 276 | ] 277 | }, 278 | { 279 | "cell_type": "code", 280 | "execution_count": 3, 281 | "metadata": {}, 282 | "outputs": [ 283 | { 284 | "data": { 285 | "text/plain": [ 286 | "['In',\n", 287 | " 'Out',\n", 288 | " '_',\n", 289 | " '_1',\n", 290 | " '_2',\n", 291 | " '__',\n", 292 | " '___',\n", 293 | " '__builtin__',\n", 294 | " '__builtins__',\n", 295 | " '__doc__',\n", 296 | " '__loader__',\n", 297 | " '__name__',\n", 298 | " '__package__',\n", 299 | " '__spec__',\n", 300 | " '_dh',\n", 301 | " '_i',\n", 302 | " '_i1',\n", 303 | " '_i2',\n", 304 | " '_i3',\n", 305 | " '_ih',\n", 306 | " '_ii',\n", 307 | " '_iii',\n", 308 | " '_oh',\n", 309 | " 'a',\n", 310 | " 'exit',\n", 311 | " 'fibo',\n", 312 | " 'get_ipython',\n", 313 | " 'quit',\n", 314 | " 'sys']" 315 | ] 316 | }, 317 | "execution_count": 3, 318 | "metadata": {}, 319 | "output_type": "execute_result" 320 | } 321 | ], 322 | "source": [ 323 | "a = [1, 2, 3, 4, 5]\n", 324 | "dir()" 325 | ] 326 | }, 327 | { 328 | "cell_type": "code", 329 | "execution_count": 4, 330 | "metadata": {}, 331 | "outputs": [ 332 | { 333 | "data": { 334 | "text/plain": [ 335 | "['ArithmeticError',\n", 336 | " 'AssertionError',\n", 337 | " 'AttributeError',\n", 338 | " 'BaseException',\n", 339 | " 'BlockingIOError',\n", 340 | " 'BrokenPipeError',\n", 341 | " 'BufferError',\n", 342 | " 'BytesWarning',\n", 343 | " 'ChildProcessError',\n", 344 | " 'ConnectionAbortedError',\n", 345 | " 'ConnectionError',\n", 346 | " 'ConnectionRefusedError',\n", 347 | " 'ConnectionResetError',\n", 348 | " 'DeprecationWarning',\n", 349 | " 'EOFError',\n", 350 | " 'Ellipsis',\n", 351 | " 'EnvironmentError',\n", 352 | " 'Exception',\n", 353 | " 'False',\n", 354 | " 'FileExistsError',\n", 355 | " 'FileNotFoundError',\n", 356 | " 'FloatingPointError',\n", 357 | " 'FutureWarning',\n", 358 | " 'GeneratorExit',\n", 359 | " 'IOError',\n", 360 | " 'ImportError',\n", 361 | " 'ImportWarning',\n", 362 | " 'IndentationError',\n", 363 | " 'IndexError',\n", 364 | " 'InterruptedError',\n", 365 | " 'IsADirectoryError',\n", 366 | " 'KeyError',\n", 367 | " 'KeyboardInterrupt',\n", 368 | " 'LookupError',\n", 369 | " 'MemoryError',\n", 370 | " 'ModuleNotFoundError',\n", 371 | " 'NameError',\n", 372 | " 'None',\n", 373 | " 'NotADirectoryError',\n", 374 | " 'NotImplemented',\n", 375 | " 'NotImplementedError',\n", 376 | " 'OSError',\n", 377 | " 'OverflowError',\n", 378 | " 'PendingDeprecationWarning',\n", 379 | " 'PermissionError',\n", 380 | " 'ProcessLookupError',\n", 381 | " 'RecursionError',\n", 382 | " 'ReferenceError',\n", 383 | " 'ResourceWarning',\n", 384 | " 'RuntimeError',\n", 385 | " 'RuntimeWarning',\n", 386 | " 'StopAsyncIteration',\n", 387 | " 'StopIteration',\n", 388 | " 'SyntaxError',\n", 389 | " 'SyntaxWarning',\n", 390 | " 'SystemError',\n", 391 | " 'SystemExit',\n", 392 | " 'TabError',\n", 393 | " 'TimeoutError',\n", 394 | " 'True',\n", 395 | " 'TypeError',\n", 396 | " 'UnboundLocalError',\n", 397 | " 'UnicodeDecodeError',\n", 398 | " 'UnicodeEncodeError',\n", 399 | " 'UnicodeError',\n", 400 | " 'UnicodeTranslateError',\n", 401 | " 'UnicodeWarning',\n", 402 | " 'UserWarning',\n", 403 | " 'ValueError',\n", 404 | " 'Warning',\n", 405 | " 'ZeroDivisionError',\n", 406 | " '__IPYTHON__',\n", 407 | " '__build_class__',\n", 408 | " '__debug__',\n", 409 | " '__doc__',\n", 410 | " '__import__',\n", 411 | " '__loader__',\n", 412 | " '__name__',\n", 413 | " '__package__',\n", 414 | " '__spec__',\n", 415 | " 'abs',\n", 416 | " 'all',\n", 417 | " 'any',\n", 418 | " 'ascii',\n", 419 | " 'bin',\n", 420 | " 'bool',\n", 421 | " 'breakpoint',\n", 422 | " 'bytearray',\n", 423 | " 'bytes',\n", 424 | " 'callable',\n", 425 | " 'chr',\n", 426 | " 'classmethod',\n", 427 | " 'compile',\n", 428 | " 'complex',\n", 429 | " 'copyright',\n", 430 | " 'credits',\n", 431 | " 'delattr',\n", 432 | " 'dict',\n", 433 | " 'dir',\n", 434 | " 'display',\n", 435 | " 'divmod',\n", 436 | " 'enumerate',\n", 437 | " 'eval',\n", 438 | " 'exec',\n", 439 | " 'filter',\n", 440 | " 'float',\n", 441 | " 'format',\n", 442 | " 'frozenset',\n", 443 | " 'get_ipython',\n", 444 | " 'getattr',\n", 445 | " 'globals',\n", 446 | " 'hasattr',\n", 447 | " 'hash',\n", 448 | " 'help',\n", 449 | " 'hex',\n", 450 | " 'id',\n", 451 | " 'input',\n", 452 | " 'int',\n", 453 | " 'isinstance',\n", 454 | " 'issubclass',\n", 455 | " 'iter',\n", 456 | " 'len',\n", 457 | " 'license',\n", 458 | " 'list',\n", 459 | " 'locals',\n", 460 | " 'map',\n", 461 | " 'max',\n", 462 | " 'memoryview',\n", 463 | " 'min',\n", 464 | " 'next',\n", 465 | " 'object',\n", 466 | " 'oct',\n", 467 | " 'open',\n", 468 | " 'ord',\n", 469 | " 'pow',\n", 470 | " 'print',\n", 471 | " 'property',\n", 472 | " 'range',\n", 473 | " 'repr',\n", 474 | " 'reversed',\n", 475 | " 'round',\n", 476 | " 'set',\n", 477 | " 'setattr',\n", 478 | " 'slice',\n", 479 | " 'sorted',\n", 480 | " 'staticmethod',\n", 481 | " 'str',\n", 482 | " 'sum',\n", 483 | " 'super',\n", 484 | " 'tuple',\n", 485 | " 'type',\n", 486 | " 'vars',\n", 487 | " 'zip']" 488 | ] 489 | }, 490 | "execution_count": 4, 491 | "metadata": {}, 492 | "output_type": "execute_result" 493 | } 494 | ], 495 | "source": [ 496 | "import builtins\n", 497 | "dir(builtins) " 498 | ] 499 | }, 500 | { 501 | "cell_type": "code", 502 | "execution_count": 5, 503 | "metadata": {}, 504 | "outputs": [ 505 | { 506 | "data": { 507 | "text/plain": [ 508 | "153" 509 | ] 510 | }, 511 | "execution_count": 5, 512 | "metadata": {}, 513 | "output_type": "execute_result" 514 | } 515 | ], 516 | "source": [ 517 | "len(dir(builtins))" 518 | ] 519 | }, 520 | { 521 | "cell_type": "markdown", 522 | "metadata": {}, 523 | "source": [ 524 | "### Packages" 525 | ] 526 | }, 527 | { 528 | "cell_type": "raw", 529 | "metadata": {}, 530 | "source": [ 531 | "sound/ Top-level package\n", 532 | " __init__.py Initialize the sound package\n", 533 | " formats/ Subpackage for file format conversions\n", 534 | " __init__.py\n", 535 | " wavread.py\n", 536 | " wavwrite.py\n", 537 | " aiffread.py\n", 538 | " aiffwrite.py\n", 539 | " auread.py\n", 540 | " auwrite.py\n", 541 | " ...\n", 542 | " effects/ Subpackage for sound effects\n", 543 | " __init__.py\n", 544 | " echo.py\n", 545 | " surround.py\n", 546 | " reverse.py\n", 547 | " ...\n", 548 | " filters/ Subpackage for filters\n", 549 | " __init__.py\n", 550 | " equalizer.py\n", 551 | " vocoder.py\n", 552 | " karaoke.py\n", 553 | " ..." 554 | ] 555 | }, 556 | { 557 | "cell_type": "code", 558 | "execution_count": null, 559 | "metadata": {}, 560 | "outputs": [], 561 | "source": [ 562 | "import sound.effects.echo\n", 563 | "sound.effects.echo.echofilter(input, output, delay=0.7, atten=4)" 564 | ] 565 | }, 566 | { 567 | "cell_type": "code", 568 | "execution_count": null, 569 | "metadata": {}, 570 | "outputs": [], 571 | "source": [ 572 | "from sound.effects import echo\n", 573 | "echo.echofilter(input, output, delay=0.7, atten=4)" 574 | ] 575 | }, 576 | { 577 | "cell_type": "code", 578 | "execution_count": null, 579 | "metadata": {}, 580 | "outputs": [], 581 | "source": [ 582 | "from sound.effects.echo import echofilter\n", 583 | "echofilter(input, output, delay=0.7, atten=4)" 584 | ] 585 | }, 586 | { 587 | "cell_type": "markdown", 588 | "metadata": {}, 589 | "source": [ 590 | "### Intra-package References" 591 | ] 592 | }, 593 | { 594 | "cell_type": "code", 595 | "execution_count": null, 596 | "metadata": {}, 597 | "outputs": [], 598 | "source": [ 599 | "from . import echo\n", 600 | "from .. import formats\n", 601 | "from ..filters import equalizer" 602 | ] 603 | } 604 | ], 605 | "metadata": { 606 | "kernelspec": { 607 | "display_name": "Python 3", 608 | "language": "python", 609 | "name": "python3" 610 | }, 611 | "language_info": { 612 | "codemirror_mode": { 613 | "name": "ipython", 614 | "version": 3 615 | }, 616 | "file_extension": ".py", 617 | "mimetype": "text/x-python", 618 | "name": "python", 619 | "nbconvert_exporter": "python", 620 | "pygments_lexer": "ipython3", 621 | "version": "3.8.5" 622 | } 623 | }, 624 | "nbformat": 4, 625 | "nbformat_minor": 4 626 | } 627 | -------------------------------------------------------------------------------- /Python Modules #6/__pycache__/fibo.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aminblm/python-ultimate-tutorial/298b388926c426bdf3c09d816b91e60b7db1c391/Python Modules #6/__pycache__/fibo.cpython-38.pyc -------------------------------------------------------------------------------- /Python Modules #6/fibo.py: -------------------------------------------------------------------------------- 1 | # Fibonacci numbers module 2 | def fib(n): # write Fibonacci series up to n 3 | a, b = 0, 1 4 | while a < n: 5 | print(a, end=' ') 6 | a, b = b, a+b 7 | print() 8 | 9 | def fib2(n): # return Fibonacci series up to n 10 | result = [] 11 | a, b = 0, 1 12 | while a < n: 13 | result.append(a) 14 | a, b = b, a+b 15 | return result 16 | 17 | if __name__ == "__main__": 18 | import sys 19 | fib(int(sys.argv[1])) 20 | print(fib2(int(sys.argv[1]))) 21 | 22 | -------------------------------------------------------------------------------- /Python Ultimate Tutorial #1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# [Amin M. Boulouma Blog](https://amboulouma.com)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Python Ultimate Tutorial #1" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "> [Reminder] 🔔\n", 22 | "- Help the creator channel reach 20k subscribers. He will keep uploading quality content for you: [Amin M. Boulouma Channel](https://www.youtube.com/channel/UCOZbokHO727qeStxeYSKMUQ?sub_confirmation=1)\n", 23 | "- This tutorial is best understood following the video playlist: [Python Ultimate Tutorial [Official Documentation]](https://www.youtube.com/watch?v=vQqisFjAnsE&list=PLpMTHmi814W0nSToTOC0Q18kREOjcJspW&index=1)" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "Hosted by Amin M. Boulouma, contact and questions: [amine.boulouma.com](https://amine.boulouma.com)\n", 31 | "- Python tutorial made simple: https://youtu.be/vQqisFjAnsE\n", 32 | "- Source code: https://amboulouma.com/python-tutorial\n", 33 | "- Github: https://github.com/amboulouma/python-ultimate-tutorial" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "### Documentation" 41 | ] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "metadata": {}, 46 | "source": [ 47 | "- Python Documentation: https://docs.python.org/3/\n", 48 | "- PEP 8: https://www.python.org/dev/peps/pep-0008/\n", 49 | "- Google Style Guide: https://google.github.io/styleguide/pyguide.html\n" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": {}, 55 | "source": [ 56 | "### Installation" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": {}, 62 | "source": [ 63 | "- Installing Anaconda: https://docs.anaconda.com/anaconda/install/\n", 64 | "- Installing Jupyter: https://jupyter.org/install\n", 65 | "- Online Jupyter notebook from Google: https://colab.research.google.com/\n", 66 | "- Installing Python: https://www.python.org/downloads/" 67 | ] 68 | }, 69 | { 70 | "cell_type": "markdown", 71 | "metadata": {}, 72 | "source": [ 73 | "> Python 3.9" 74 | ] 75 | }, 76 | { 77 | "cell_type": "markdown", 78 | "metadata": {}, 79 | "source": [ 80 | "## Table of content" 81 | ] 82 | }, 83 | { 84 | "cell_type": "markdown", 85 | "metadata": {}, 86 | "source": [ 87 | "- [1. Setting up the environment with Jupyter Notebook](https://youtu.be/vQqisFjAnsE)\n", 88 | "\n", 89 | "- [2. A simple Introduction to Python](https://youtu.be/vQqisFjAnsE)\n", 90 | "\n", 91 | "- [3. Create a calculator with Python](https://youtu.be/vQqisFjAnsE)\n", 92 | " - [3.1. Numbers](https://youtu.be/vQqisFjAnsE)\n", 93 | " - [3.2. Strings](https://youtu.be/vQqisFjAnsE)\n", 94 | " - [3.3. Lists](https://youtu.be/vQqisFjAnsE)\n", 95 | " - [3.4. First Steps Towards Programming](https://youtu.be/vQqisFjAnsE)\n", 96 | "\n", 97 | "- [4. Control Flow Tools](https://youtu.be/vQqisFjAnsE)\n", 98 | " - [4.1. if Statements](https://youtu.be/vQqisFjAnsE)\n", 99 | " - [4.2. for Statements](https://youtu.be/vQqisFjAnsE)\n", 100 | " - [4.3. The range() Function](https://youtu.be/vQqisFjAnsE)\n", 101 | " - [4.4. break and continue Statements, and else Clauses on Loops](https://youtu.be/vQqisFjAnsE)\n", 102 | " - [4.5. pass Statements](https://youtu.be/vQqisFjAnsE)\n", 103 | " - [4.6. Defining Functions](https://youtu.be/vQqisFjAnsE)\n", 104 | " - [4.7. More on Defining Functions](https://youtu.be/vQqisFjAnsE)\n", 105 | " - [4.7.1. Default Argument Values](https://youtu.be/vQqisFjAnsE)\n", 106 | " - [4.7.2. Keyword Arguments](https://youtu.be/vQqisFjAnsE)\n", 107 | " - [4.7.3. Special parameters](https://youtu.be/vQqisFjAnsE)\n", 108 | " - [4.7.3.1. Positional-or-Keyword Arguments](https://youtu.be/vQqisFjAnsE)\n", 109 | " - [4.7.3.2. Positional-Only Parameters](https://youtu.be/vQqisFjAnsE)\n", 110 | " - [4.7.3.3. Keyword-Only Arguments](https://youtu.be/vQqisFjAnsE)\n", 111 | " - [4.7.3.4. Function Examples](https://youtu.be/vQqisFjAnsE)\n", 112 | " - [4.7.3.5. Recap](https://youtu.be/vQqisFjAnsE)\n", 113 | " - [4.7.4. Arbitrary Argument Lists](https://youtu.be/vQqisFjAnsE)\n", 114 | " - [4.7.5. Unpacking Argument Lists](https://youtu.be/vQqisFjAnsE)\n", 115 | " - [4.7.6. Lambda Expressions](https://youtu.be/vQqisFjAnsE)\n", 116 | " - [4.7.7. Documentation Strings](https://youtu.be/vQqisFjAnsE)\n", 117 | " - [4.7.8. Function Annotations](https://youtu.be/vQqisFjAnsE)\n", 118 | " - [4.8. Intermezzo: Coding Style](https://youtu.be/vQqisFjAnsE)\n", 119 | "\n", 120 | "- [5. Data Structures](https://youtu.be/vQqisFjAnsE)\n", 121 | " - [5.1. More on Lists](https://youtu.be/vQqisFjAnsE)\n", 122 | " - [5.1.1. Using Lists as Stacks](https://youtu.be/vQqisFjAnsE)\n", 123 | " - [5.1.2. Using Lists as Queues](https://youtu.be/vQqisFjAnsE)\n", 124 | " - [5.1.3. List Comprehensions](https://youtu.be/vQqisFjAnsE)\n", 125 | " - [5.1.4. Nested List Comprehensions](https://youtu.be/vQqisFjAnsE)\n", 126 | " - [5.2. The del statement](https://youtu.be/vQqisFjAnsE)\n", 127 | " - [5.3. Tuples and Sequences](https://youtu.be/vQqisFjAnsE)\n", 128 | " - [5.4. Sets](https://youtu.be/vQqisFjAnsE)\n", 129 | " - [5.5. Dictionaries](https://youtu.be/vQqisFjAnsE)\n", 130 | " - [5.6. Looping Techniques](https://youtu.be/vQqisFjAnsE)\n", 131 | " - [5.7. More on Conditions](https://youtu.be/vQqisFjAnsE)\n", 132 | " - [5.8. Comparing Sequences and Other Types](https://youtu.be/vQqisFjAnsE)\n", 133 | "\n", 134 | "- [6. Modules](https://youtu.be/vQqisFjAnsE)\n", 135 | " - [6.1. More on Modules](https://youtu.be/vQqisFjAnsE)\n", 136 | " - [6.1.1. Executing modules as scripts](https://youtu.be/vQqisFjAnsE)\n", 137 | " - [6.1.2. The Module Search Path](https://youtu.be/vQqisFjAnsE)\n", 138 | " - [6.1.3. “Compiled” Python files](https://youtu.be/vQqisFjAnsE)\n", 139 | " - [6.2. Standard Modules](https://youtu.be/vQqisFjAnsE)\n", 140 | " - [6.3. The dir() Function](https://youtu.be/vQqisFjAnsE)\n", 141 | " - [6.4. Packages](https://youtu.be/vQqisFjAnsE)\n", 142 | " - [6.4.1. Importing * From a Package](https://youtu.be/vQqisFjAnsE)\n", 143 | " - [6.4.2. Intra-package References](https://youtu.be/vQqisFjAnsE)\n", 144 | " - [6.4.3. Packages in Multiple Directories](https://youtu.be/vQqisFjAnsE)\n", 145 | "\n", 146 | "- [7. Input and Output](https://youtu.be/vQqisFjAnsE)\n", 147 | " - [7.1. Fancier Output Formatting](https://youtu.be/vQqisFjAnsE)\n", 148 | " - [7.1.1. Formatted String Literals](https://youtu.be/vQqisFjAnsE)\n", 149 | " - [7.1.2. The String format() Method](https://youtu.be/vQqisFjAnsE)\n", 150 | " - [7.1.3. Manual String Formatting](https://youtu.be/vQqisFjAnsE)\n", 151 | " - [7.1.4. Old string formatting](https://youtu.be/vQqisFjAnsE)\n", 152 | " - [7.2. Reading and Writing Files](https://youtu.be/vQqisFjAnsE)\n", 153 | " - [7.2.1. Methods of File Objects](https://youtu.be/vQqisFjAnsE)\n", 154 | " - [7.2.2. Saving structured data with json](https://youtu.be/vQqisFjAnsE)\n", 155 | "\n", 156 | "- [8. Errors and Exceptions](https://youtu.be/vQqisFjAnsE)\n", 157 | " - [8.1. Syntax Errors](https://youtu.be/vQqisFjAnsE)\n", 158 | " - [8.2. Exceptions](https://youtu.be/vQqisFjAnsE)\n", 159 | " - [8.3. Handling Exceptions](https://youtu.be/vQqisFjAnsE)\n", 160 | " - [8.4. Raising Exceptions](https://youtu.be/vQqisFjAnsE)\n", 161 | " - [8.5. Exception Chaining](https://youtu.be/vQqisFjAnsE)\n", 162 | " - [8.6. User-defined Exceptions](https://youtu.be/vQqisFjAnsE)\n", 163 | " - [8.7. Defining Clean-up Actions](https://youtu.be/vQqisFjAnsE)\n", 164 | " - [8.8. Predefined Clean-up Actions](https://youtu.be/vQqisFjAnsE)\n", 165 | "\n", 166 | "- [9. Classes](https://youtu.be/vQqisFjAnsE)\n", 167 | " - [9.1. A Word About Names and Objects](https://youtu.be/vQqisFjAnsE)\n", 168 | " - [9.2. Python Scopes and Namespaces](https://youtu.be/vQqisFjAnsE)\n", 169 | " - [9.2.1. Scopes and Namespaces Example](https://youtu.be/vQqisFjAnsE)\n", 170 | " - [9.3. A First Look at Classes](https://youtu.be/vQqisFjAnsE)\n", 171 | " - [9.3.1. Class Definition Syntax](https://youtu.be/vQqisFjAnsE)\n", 172 | " - [9.3.2. Class Objects](https://youtu.be/vQqisFjAnsE)\n", 173 | " - [9.3.3. Instance Objects](https://youtu.be/vQqisFjAnsE)\n", 174 | " - [9.3.4. Method Objects](https://youtu.be/vQqisFjAnsE)\n", 175 | " - [9.3.5. Class and Instance Variables](https://youtu.be/vQqisFjAnsE)\n", 176 | " - [9.4. Random Remarks](https://youtu.be/vQqisFjAnsE)\n", 177 | " - [9.5. Inheritance](https://youtu.be/vQqisFjAnsE)\n", 178 | " - [9.5.1. Multiple Inheritance](https://youtu.be/vQqisFjAnsE)\n", 179 | " - [9.6. Private Variables](https://youtu.be/vQqisFjAnsE)\n", 180 | " - [9.7. Odds and Ends](https://youtu.be/vQqisFjAnsE)\n", 181 | " - [9.8. Iterators](https://youtu.be/vQqisFjAnsE)\n", 182 | " - [9.9. Generators](https://youtu.be/vQqisFjAnsE)\n", 183 | " - [9.10. Generator Expressions](https://youtu.be/vQqisFjAnsE)\n", 184 | "\n", 185 | "- [10. Brief Tour of the Standard Library](https://youtu.be/vQqisFjAnsE)\n", 186 | " - [10.1. Operating System Interface](https://youtu.be/vQqisFjAnsE)\n", 187 | " - [10.2. File Wildcards](https://youtu.be/vQqisFjAnsE)\n", 188 | " - [10.3. Command Line Arguments](https://youtu.be/vQqisFjAnsE)\n", 189 | " - [10.4. Error Output Redirection and Program Termination](https://youtu.be/vQqisFjAnsE)\n", 190 | " - [10.5. String Pattern Matching](https://youtu.be/vQqisFjAnsE)\n", 191 | " - [10.6. Mathematics](https://youtu.be/vQqisFjAnsE)\n", 192 | " - [10.7. Internet Access](https://youtu.be/vQqisFjAnsE)\n", 193 | " - [10.8. Dates and Times](https://youtu.be/vQqisFjAnsE)\n", 194 | " - [10.9. Data Compression](https://youtu.be/vQqisFjAnsE)\n", 195 | " - [10.10. Performance Measurement](https://youtu.be/vQqisFjAnsE)\n", 196 | " - [10.11. Quality Control](https://youtu.be/vQqisFjAnsE)\n", 197 | " - [10.12. Batteries Included](https://youtu.be/vQqisFjAnsE)\n", 198 | "\n", 199 | "- [11. Brief Tour of the Standard Library — Part II](https://youtu.be/vQqisFjAnsE)\n", 200 | " - [11.1. Output Formatting](https://youtu.be/vQqisFjAnsE)\n", 201 | " - [11.2. Templating](https://youtu.be/vQqisFjAnsE)\n", 202 | " - [11.3. Working with Binary Data Record Layouts](https://youtu.be/vQqisFjAnsE)\n", 203 | " - [11.4. Multi-threading](https://youtu.be/vQqisFjAnsE)\n", 204 | " - [11.5. Logging](https://youtu.be/vQqisFjAnsE)\n", 205 | " - [11.6. Weak References](https://youtu.be/vQqisFjAnsE)\n", 206 | " - [11.7. Tools for Working with Lists](https://youtu.be/vQqisFjAnsE)\n", 207 | " - [11.8. Decimal Floating Point Arithmetic](https://youtu.be/vQqisFjAnsE)\n", 208 | "\n", 209 | "- [12. Virtual Environments and Packages](https://youtu.be/vQqisFjAnsE)\n", 210 | " - [12.1. Introduction](https://youtu.be/vQqisFjAnsE)\n", 211 | " - [12.2. Creating Virtual Environments](https://youtu.be/vQqisFjAnsE)\n", 212 | " - [12.3. Managing Packages with pip](https://youtu.be/vQqisFjAnsE)\n", 213 | "\n", 214 | "- [13. PEP 8 - Style Guide for Python code](https://youtu.be/vQqisFjAnsE)\n", 215 | "\n", 216 | " - [13.1. Introduction](https://youtu.be/vQqisFjAnsE)\n", 217 | "\n", 218 | " - [13.2. A Foolish Consistency is the Hobgoblin of Little Minds](https://youtu.be/vQqisFjAnsE)\n", 219 | "\n", 220 | " - [13.3. Code Lay-out](https://youtu.be/vQqisFjAnsE)\n", 221 | " - [13.3.1. Indentation](https://youtu.be/vQqisFjAnsE)\n", 222 | " - [13.3.2. Tabs or Spaces?](https://youtu.be/vQqisFjAnsE)\n", 223 | " - [13.3.3. Maximum Line Length](https://youtu.be/vQqisFjAnsE)\n", 224 | " - [13.3.4. Should a Line Break Before or After a Binary Operator?](https://youtu.be/vQqisFjAnsE)\n", 225 | " - [13.3.5. Blank Lines](https://youtu.be/vQqisFjAnsE)\n", 226 | " - [13.3.6. Source File Encoding](https://youtu.be/vQqisFjAnsE)\n", 227 | " - [13.3.7. Imports](https://youtu.be/vQqisFjAnsE)\n", 228 | " - [13.3.8. Module Level Dunder Names](https://youtu.be/vQqisFjAnsE)\n", 229 | "\n", 230 | " - [13.4. String Quotes](https://youtu.be/vQqisFjAnsE)\n", 231 | "\n", 232 | " - [13.5. Whitespace in Expressions and Statements](https://youtu.be/vQqisFjAnsE)\n", 233 | " - [13.5.1. Pet Peeves](https://youtu.be/vQqisFjAnsE)\n", 234 | " - [13.5.2. Other Recommendations](https://youtu.be/vQqisFjAnsE)\n", 235 | "\n", 236 | " - [13.6. When to Use Trailing Commas](https://youtu.be/vQqisFjAnsE)\n", 237 | "\n", 238 | " - [13.7. Comments](https://youtu.be/vQqisFjAnsE)\n", 239 | " - [13.7.1. Block Comments](https://youtu.be/vQqisFjAnsE)\n", 240 | " - [13.7.2. Inline Comments](https://youtu.be/vQqisFjAnsE)\n", 241 | " - [13.7.3. Documentation Strings](https://youtu.be/vQqisFjAnsE)\n", 242 | "\n", 243 | " - [13.8. Naming Conventions](https://youtu.be/vQqisFjAnsE)\n", 244 | " - [13.8.1. Overriding Principle](https://youtu.be/vQqisFjAnsE)\n", 245 | " - [13.8.2. Descriptive: Naming Styles](https://youtu.be/vQqisFjAnsE)\n", 246 | " - [13.8.3. Prescriptive: Naming Conventions](https://youtu.be/vQqisFjAnsE)\n", 247 | " - [13.8.3.1. Names to Avoid](https://youtu.be/vQqisFjAnsE)\n", 248 | " - [13.8.3.2. ASCII Compatibility](https://youtu.be/vQqisFjAnsE)\n", 249 | " - [13.8.3.3. Package and Module Names](https://youtu.be/vQqisFjAnsE)\n", 250 | " - [13.8.3.4. Class Names](https://youtu.be/vQqisFjAnsE)\n", 251 | " - [13.8.3.5. Type Variable Names](https://youtu.be/vQqisFjAnsE)\n", 252 | " - [13.8.3.6. Exception Names](https://youtu.be/vQqisFjAnsE)\n", 253 | " - [13.8.3.7. Global Variable Names](https://youtu.be/vQqisFjAnsE)\n", 254 | " - [13.8.3.8. Function and Variable Names](https://youtu.be/vQqisFjAnsE)\n", 255 | " - [13.8.3.9. Function and Method Arguments](https://youtu.be/vQqisFjAnsE)\n", 256 | " - [13.8.3.10. Method Names and Instance Variables](https://youtu.be/vQqisFjAnsE)\n", 257 | " - [13.8.3.11. Constants](https://youtu.be/vQqisFjAnsE)\n", 258 | " - [13.8.3.12. Designing for Inheritance](https://youtu.be/vQqisFjAnsE)\n", 259 | " - [13.8.4. Public and Internal Interfaces](https://youtu.be/vQqisFjAnsE)\n", 260 | "\n", 261 | " - [13.9. Programming Recommendations](https://youtu.be/vQqisFjAnsE)\n", 262 | " - [13.9.1. Function Annotations](https://youtu.be/vQqisFjAnsE)\n", 263 | " - [13.9.2. Variable Annotations](https://youtu.be/vQqisFjAnsE)\n", 264 | "\n", 265 | "- [14. [BONUS] Google Python Style Guide](https://youtu.be/vQqisFjAnsE)\n", 266 | "\n", 267 | " - [14.1. Background](https://youtu.be/vQqisFjAnsE)\n", 268 | "\n", 269 | " - [14.2. Python Language Rules](https://youtu.be/vQqisFjAnsE)\n", 270 | " - [14.2.1. Lint](https://youtu.be/vQqisFjAnsE)\n", 271 | " - [14.2.2. Imports](https://youtu.be/vQqisFjAnsE)\n", 272 | " - [14.2.3. Packages](https://youtu.be/vQqisFjAnsE)\n", 273 | " - [14.2.4. Exceptions](https://youtu.be/vQqisFjAnsE)\n", 274 | " - [14.2.5. Global variables](https://youtu.be/vQqisFjAnsE)\n", 275 | " - [14.2.6. Nested/Local/Inner Classes and Functions](https://youtu.be/vQqisFjAnsE)\n", 276 | " - [14.2.7. Comprehensions & Generator Expressions](https://youtu.be/vQqisFjAnsE)\n", 277 | " - [14.2.8. Default Iterators and Operators](https://youtu.be/vQqisFjAnsE)\n", 278 | " - [14.2.9. Generators](https://youtu.be/vQqisFjAnsE)\n", 279 | " - [14.2.10. Lambda Functions](https://youtu.be/vQqisFjAnsE)\n", 280 | " - [14.2.11. Conditional Expressions](https://youtu.be/vQqisFjAnsE)\n", 281 | " - [14.2.12. Default Argument Values](https://youtu.be/vQqisFjAnsE)\n", 282 | " - [14.2.13. Properties](https://youtu.be/vQqisFjAnsE)\n", 283 | " - [14.2.14. True/False Evaluations](https://youtu.be/vQqisFjAnsE)\n", 284 | " - [14.2.16. Lexical Scoping](https://youtu.be/vQqisFjAnsE)\n", 285 | " - [14.2.17. Function and Method Decorators](https://youtu.be/vQqisFjAnsE)\n", 286 | " - [14.2.18. Threading](https://youtu.be/vQqisFjAnsE)\n", 287 | " - [14.2.19. Power Features](https://youtu.be/vQqisFjAnsE)\n", 288 | " - [14.2.20. Modern Python: Python 3 and from \\_\\_future__ imports](https://youtu.be/vQqisFjAnsE)\n", 289 | " - [14.2.21. Type Annotated Code](https://youtu.be/vQqisFjAnsE)\n", 290 | "\n", 291 | " - [14.3. Python Style Rules](https://youtu.be/vQqisFjAnsE)\n", 292 | " - [14.3.1. Semicolons](https://youtu.be/vQqisFjAnsE)\n", 293 | " - [14.3.2. Line length](https://youtu.be/vQqisFjAnsE)\n", 294 | " - [14.3.3. Parentheses](https://youtu.be/vQqisFjAnsE)\n", 295 | " - [14.3.4. Indentation](https://youtu.be/vQqisFjAnsE)\n", 296 | " - [14.3.4.1. Trailing commas in sequences of items?](https://youtu.be/vQqisFjAnsE)\n", 297 | " - [14.3.5. Blank Lines](https://youtu.be/vQqisFjAnsE)\n", 298 | " - [14.3.6. Whitespace](https://youtu.be/vQqisFjAnsE)\n", 299 | " - [14.3.7. Shebang Line](https://youtu.be/vQqisFjAnsE)\n", 300 | " - [14.3.8. Comments and Docstrings](https://youtu.be/vQqisFjAnsE)\n", 301 | " - [14.3.8.1. Docstrings](https://youtu.be/vQqisFjAnsE)\n", 302 | " - [14.3.8.2. Modules](https://youtu.be/vQqisFjAnsE)\n", 303 | " - [14.3.8.3. Functions and Methods](https://youtu.be/vQqisFjAnsE)\n", 304 | " - [14.3.8.4. Classes](https://youtu.be/vQqisFjAnsE)\n", 305 | " - [14.3.8.5. Block and Inline Comments](https://youtu.be/vQqisFjAnsE)\n", 306 | " - [14.3.8.6. Punctuation, Spelling, and Grammar](https://youtu.be/vQqisFjAnsE)\n", 307 | " - [14.3.10. Strings](https://youtu.be/vQqisFjAnsE)\n", 308 | " - [14.3.10.1. Logging](https://youtu.be/vQqisFjAnsE)\n", 309 | " - [14.3.10.2. Error Messages](https://youtu.be/vQqisFjAnsE)\n", 310 | " - [14.3.11. Files and Sockets](https://youtu.be/vQqisFjAnsE)\n", 311 | " - [14.3.12. TODO Comments](https://youtu.be/vQqisFjAnsE)\n", 312 | " - [14.3.13. Imports formatting](https://youtu.be/vQqisFjAnsE)\n", 313 | " - [14.3.14. Statements](https://youtu.be/vQqisFjAnsE)\n", 314 | " - [14.3.15. Accessors](https://youtu.be/vQqisFjAnsE)\n", 315 | " - [14.3.16. Naming](https://youtu.be/vQqisFjAnsE)\n", 316 | " - [14.3.16.1. Names to Avoid](https://youtu.be/vQqisFjAnsE)\n", 317 | " - [14.3.16.2. Naming Conventions](https://youtu.be/vQqisFjAnsE)\n", 318 | " - [14.3.16.3. File Naming](https://youtu.be/vQqisFjAnsE)\n", 319 | " - [14.3.16.4. Guidelines derived from Guido’s Recommendations](https://youtu.be/vQqisFjAnsE)\n", 320 | " - [14.3.17. Main](https://youtu.be/vQqisFjAnsE)\n", 321 | " - [14.3.18. Function length](https://youtu.be/vQqisFjAnsE)\n", 322 | " - [14.3.19. Type Annotations](https://youtu.be/vQqisFjAnsE)\n", 323 | " - [14.3.19.1. General Rules](https://youtu.be/vQqisFjAnsE)\n", 324 | " - [14.3.19.2. Line Breaking](https://youtu.be/vQqisFjAnsE)\n", 325 | " - [14.3.19.3. Forward Declarations](https://youtu.be/vQqisFjAnsE)\n", 326 | " - [14.3.19.4. Default Values](https://youtu.be/vQqisFjAnsE)\n", 327 | " - [14.3.19.5. NoneType](https://youtu.be/vQqisFjAnsE)\n", 328 | " - [14.3.19.6. Type Aliases](https://youtu.be/vQqisFjAnsE)\n", 329 | " - [14.3.19.7. Ignoring Types](https://youtu.be/vQqisFjAnsE)\n", 330 | " - [14.3.19.8. Typing Variables](https://youtu.be/vQqisFjAnsE)\n", 331 | " - [14.3.19.9. Tuples vs Lists](https://youtu.be/vQqisFjAnsE)\n", 332 | " - [14.3.19.10. TypeVars](https://youtu.be/vQqisFjAnsE)\n", 333 | " - [14.3.19.11. String types](https://youtu.be/vQqisFjAnsE)\n", 334 | " - [14.3.19.12. Imports For Typing](https://youtu.be/vQqisFjAnsE)\n", 335 | " - [14.3.19.13. Conditional Imports](https://youtu.be/vQqisFjAnsE)\n", 336 | " - [14.3.19.14. Circular Dependencies](https://youtu.be/vQqisFjAnsE)\n", 337 | " - [14.3.19.15. Generics](https://youtu.be/vQqisFjAnsE)\n", 338 | " - [14.3.19.16. Build Dependencies](https://youtu.be/vQqisFjAnsE)\n", 339 | "\n", 340 | " - [14.4. Parting Words](https://youtu.be/vQqisFjAnsE)\n", 341 | "- [15. Python libraries](https://youtu.be/vQqisFjAnsE)\n", 342 | "- [16. Python integretions with other technologies](https://youtu.be/vQqisFjAnsE)\n", 343 | "- [17. Python Web technologies](https://youtu.be/vQqisFjAnsE)\n", 344 | "- [18. Python Machine Learning](https://youtu.be/vQqisFjAnsE)\n", 345 | "- [19. Python automation](https://youtu.be/vQqisFjAnsE)\n", 346 | "- [20. Python modules](https://youtu.be/vQqisFjAnsE)\n", 347 | "- [21. Python coding challenges](https://youtu.be/vQqisFjAnsE)" 348 | ] 349 | } 350 | ], 351 | "metadata": { 352 | "kernelspec": { 353 | "display_name": "Python 3", 354 | "language": "python", 355 | "name": "python3" 356 | }, 357 | "language_info": { 358 | "codemirror_mode": { 359 | "name": "ipython", 360 | "version": 3 361 | }, 362 | "file_extension": ".py", 363 | "mimetype": "text/x-python", 364 | "name": "python", 365 | "nbconvert_exporter": "python", 366 | "pygments_lexer": "ipython3", 367 | "version": "3.8.5" 368 | } 369 | }, 370 | "nbformat": 4, 371 | "nbformat_minor": 4 372 | } 373 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python Ultimate Tutorial 2 | 3 | > [Reminder] 🔔 4 | - Help the creator channel reach 20k subscribers. He will keep uploading quality content for you: [Amin M. Boulouma Channel](https://www.youtube.com/channel/UCOZbokHO727qeStxeYSKMUQ?sub_confirmation=1) 5 | - This tutorial is best understood following the video playlist: [Python Ultimate Tutorial](https://www.youtube.com/playlist?list=PLpMTHmi814W0nSToTOC0Q18kREOjcJspW) 6 | 7 | 8 | Hosted by Amin M. Boulouma, contact and questions: [amine.boulouma.com](https://amine.boulouma.com) 9 | 10 | - Python tutorial made simple: https://youtu.be/vQqisFjAnsE 11 | - Source code: https://amboulouma.com/python-tutorial 12 | - Amin M. Boulouma Blog: https://amboulouma.com 13 | - Github: https://github.com/amboulouma/python-ultimate-tutorial 14 | 15 | ### Documentation 16 | 17 | - Python Documentation: https://docs.python.org/3/ 18 | - PEP 8: https://www.python.org/dev/peps/pep-0008/ 19 | - Google Style Guide: https://google.github.io/styleguide/pyguide.html 20 | 21 | 22 | ### Installation 23 | 24 | - Installing Anaconda: https://docs.anaconda.com/anaconda/install/ 25 | - Installing Jupyter: https://jupyter.org/install 26 | - Online Jupyter notebook from Google: https://colab.research.google.com/ 27 | - Installing Python: https://www.python.org/downloads/ 28 | 29 | > Python 3.9 30 | 31 | ## Table of content 32 | 33 | - [1. Setting up the environment with Jupyter Notebook](https://youtu.be/vQqisFjAnsE) 34 | 35 | - [2. A simple Introduction to Python](https://youtu.be/vQqisFjAnsE) 36 | 37 | - [3. Create a calculator with Python](https://youtu.be/vQqisFjAnsE) 38 | - [3.1. Numbers](https://youtu.be/vQqisFjAnsE) 39 | - [3.2. Strings](https://youtu.be/vQqisFjAnsE) 40 | - [3.3. Lists](https://youtu.be/vQqisFjAnsE) 41 | - [3.4. First Steps Towards Programming](https://youtu.be/vQqisFjAnsE) 42 | 43 | - [4. Control Flow Tools](https://youtu.be/vQqisFjAnsE) 44 | - [4.1. if Statements](https://youtu.be/vQqisFjAnsE) 45 | - [4.2. for Statements](https://youtu.be/vQqisFjAnsE) 46 | - [4.3. The range() Function](https://youtu.be/vQqisFjAnsE) 47 | - [4.4. break and continue Statements, and else Clauses on Loops](https://youtu.be/vQqisFjAnsE) 48 | - [4.5. pass Statements](https://youtu.be/vQqisFjAnsE) 49 | - [4.6. Defining Functions](https://youtu.be/vQqisFjAnsE) 50 | - [4.7. More on Defining Functions](https://youtu.be/vQqisFjAnsE) 51 | - [4.7.1. Default Argument Values](https://youtu.be/vQqisFjAnsE) 52 | - [4.7.2. Keyword Arguments](https://youtu.be/vQqisFjAnsE) 53 | - [4.7.3. Special parameters](https://youtu.be/vQqisFjAnsE) 54 | - [4.7.3.1. Positional-or-Keyword Arguments](https://youtu.be/vQqisFjAnsE) 55 | - [4.7.3.2. Positional-Only Parameters](https://youtu.be/vQqisFjAnsE) 56 | - [4.7.3.3. Keyword-Only Arguments](https://youtu.be/vQqisFjAnsE) 57 | - [4.7.3.4. Function Examples](https://youtu.be/vQqisFjAnsE) 58 | - [4.7.3.5. Recap](https://youtu.be/vQqisFjAnsE) 59 | - [4.7.4. Arbitrary Argument Lists](https://youtu.be/vQqisFjAnsE) 60 | - [4.7.5. Unpacking Argument Lists](https://youtu.be/vQqisFjAnsE) 61 | - [4.7.6. Lambda Expressions](https://youtu.be/vQqisFjAnsE) 62 | - [4.7.7. Documentation Strings](https://youtu.be/vQqisFjAnsE) 63 | - [4.7.8. Function Annotations](https://youtu.be/vQqisFjAnsE) 64 | - [4.8. Intermezzo: Coding Style](https://youtu.be/vQqisFjAnsE) 65 | 66 | - [5. Data Structures](https://youtu.be/vQqisFjAnsE) 67 | - [5.1. More on Lists](https://youtu.be/vQqisFjAnsE) 68 | - [5.1.1. Using Lists as Stacks](https://youtu.be/vQqisFjAnsE) 69 | - [5.1.2. Using Lists as Queues](https://youtu.be/vQqisFjAnsE) 70 | - [5.1.3. List Comprehensions](https://youtu.be/vQqisFjAnsE) 71 | - [5.1.4. Nested List Comprehensions](https://youtu.be/vQqisFjAnsE) 72 | - [5.2. The del statement](https://youtu.be/vQqisFjAnsE) 73 | - [5.3. Tuples and Sequences](https://youtu.be/vQqisFjAnsE) 74 | - [5.4. Sets](https://youtu.be/vQqisFjAnsE) 75 | - [5.5. Dictionaries](https://youtu.be/vQqisFjAnsE) 76 | - [5.6. Looping Techniques](https://youtu.be/vQqisFjAnsE) 77 | - [5.7. More on Conditions](https://youtu.be/vQqisFjAnsE) 78 | - [5.8. Comparing Sequences and Other Types](https://youtu.be/vQqisFjAnsE) 79 | 80 | - [6. Modules](https://youtu.be/vQqisFjAnsE) 81 | - [6.1. More on Modules](https://youtu.be/vQqisFjAnsE) 82 | - [6.1.1. Executing modules as scripts](https://youtu.be/vQqisFjAnsE) 83 | - [6.1.2. The Module Search Path](https://youtu.be/vQqisFjAnsE) 84 | - [6.1.3. “Compiled” Python files](https://youtu.be/vQqisFjAnsE) 85 | - [6.2. Standard Modules](https://youtu.be/vQqisFjAnsE) 86 | - [6.3. The dir() Function](https://youtu.be/vQqisFjAnsE) 87 | - [6.4. Packages](https://youtu.be/vQqisFjAnsE) 88 | - [6.4.1. Importing * From a Package](https://youtu.be/vQqisFjAnsE) 89 | - [6.4.2. Intra-package References](https://youtu.be/vQqisFjAnsE) 90 | - [6.4.3. Packages in Multiple Directories](https://youtu.be/vQqisFjAnsE) 91 | 92 | - [7. Input and Output](https://youtu.be/vQqisFjAnsE) 93 | - [7.1. Fancier Output Formatting](https://youtu.be/vQqisFjAnsE) 94 | - [7.1.1. Formatted String Literals](https://youtu.be/vQqisFjAnsE) 95 | - [7.1.2. The String format() Method](https://youtu.be/vQqisFjAnsE) 96 | - [7.1.3. Manual String Formatting](https://youtu.be/vQqisFjAnsE) 97 | - [7.1.4. Old string formatting](https://youtu.be/vQqisFjAnsE) 98 | - [7.2. Reading and Writing Files](https://youtu.be/vQqisFjAnsE) 99 | - [7.2.1. Methods of File Objects](https://youtu.be/vQqisFjAnsE) 100 | - [7.2.2. Saving structured data with json](https://youtu.be/vQqisFjAnsE) 101 | 102 | - [8. Errors and Exceptions](https://youtu.be/vQqisFjAnsE) 103 | - [8.1. Syntax Errors](https://youtu.be/vQqisFjAnsE) 104 | - [8.2. Exceptions](https://youtu.be/vQqisFjAnsE) 105 | - [8.3. Handling Exceptions](https://youtu.be/vQqisFjAnsE) 106 | - [8.4. Raising Exceptions](https://youtu.be/vQqisFjAnsE) 107 | - [8.5. Exception Chaining](https://youtu.be/vQqisFjAnsE) 108 | - [8.6. User-defined Exceptions](https://youtu.be/vQqisFjAnsE) 109 | - [8.7. Defining Clean-up Actions](https://youtu.be/vQqisFjAnsE) 110 | - [8.8. Predefined Clean-up Actions](https://youtu.be/vQqisFjAnsE) 111 | 112 | - [9. Classes](https://youtu.be/vQqisFjAnsE) 113 | - [9.1. A Word About Names and Objects](https://youtu.be/vQqisFjAnsE) 114 | - [9.2. Python Scopes and Namespaces](https://youtu.be/vQqisFjAnsE) 115 | - [9.2.1. Scopes and Namespaces Example](https://youtu.be/vQqisFjAnsE) 116 | - [9.3. A First Look at Classes](https://youtu.be/vQqisFjAnsE) 117 | - [9.3.1. Class Definition Syntax](https://youtu.be/vQqisFjAnsE) 118 | - [9.3.2. Class Objects](https://youtu.be/vQqisFjAnsE) 119 | - [9.3.3. Instance Objects](https://youtu.be/vQqisFjAnsE) 120 | - [9.3.4. Method Objects](https://youtu.be/vQqisFjAnsE) 121 | - [9.3.5. Class and Instance Variables](https://youtu.be/vQqisFjAnsE) 122 | - [9.4. Random Remarks](https://youtu.be/vQqisFjAnsE) 123 | - [9.5. Inheritance](https://youtu.be/vQqisFjAnsE) 124 | - [9.5.1. Multiple Inheritance](https://youtu.be/vQqisFjAnsE) 125 | - [9.6. Private Variables](https://youtu.be/vQqisFjAnsE) 126 | - [9.7. Odds and Ends](https://youtu.be/vQqisFjAnsE) 127 | - [9.8. Iterators](https://youtu.be/vQqisFjAnsE) 128 | - [9.9. Generators](https://youtu.be/vQqisFjAnsE) 129 | - [9.10. Generator Expressions](https://youtu.be/vQqisFjAnsE) 130 | 131 | - [10. Brief Tour of the Standard Library](https://youtu.be/vQqisFjAnsE) 132 | - [10.1. Operating System Interface](https://youtu.be/vQqisFjAnsE) 133 | - [10.2. File Wildcards](https://youtu.be/vQqisFjAnsE) 134 | - [10.3. Command Line Arguments](https://youtu.be/vQqisFjAnsE) 135 | - [10.4. Error Output Redirection and Program Termination](https://youtu.be/vQqisFjAnsE) 136 | - [10.5. String Pattern Matching](https://youtu.be/vQqisFjAnsE) 137 | - [10.6. Mathematics](https://youtu.be/vQqisFjAnsE) 138 | - [10.7. Internet Access](https://youtu.be/vQqisFjAnsE) 139 | - [10.8. Dates and Times](https://youtu.be/vQqisFjAnsE) 140 | - [10.9. Data Compression](https://youtu.be/vQqisFjAnsE) 141 | - [10.10. Performance Measurement](https://youtu.be/vQqisFjAnsE) 142 | - [10.11. Quality Control](https://youtu.be/vQqisFjAnsE) 143 | - [10.12. Batteries Included](https://youtu.be/vQqisFjAnsE) 144 | 145 | - [11. Brief Tour of the Standard Library — Part II](https://youtu.be/vQqisFjAnsE) 146 | - [11.1. Output Formatting](https://youtu.be/vQqisFjAnsE) 147 | - [11.2. Templating](https://youtu.be/vQqisFjAnsE) 148 | - [11.3. Working with Binary Data Record Layouts](https://youtu.be/vQqisFjAnsE) 149 | - [11.4. Multi-threading](https://youtu.be/vQqisFjAnsE) 150 | - [11.5. Logging](https://youtu.be/vQqisFjAnsE) 151 | - [11.6. Weak References](https://youtu.be/vQqisFjAnsE) 152 | - [11.7. Tools for Working with Lists](https://youtu.be/vQqisFjAnsE) 153 | - [11.8. Decimal Floating Point Arithmetic](https://youtu.be/vQqisFjAnsE) 154 | 155 | - [12. Virtual Environments and Packages](https://youtu.be/vQqisFjAnsE) 156 | - [12.1. Introduction](https://youtu.be/vQqisFjAnsE) 157 | - [12.2. Creating Virtual Environments](https://youtu.be/vQqisFjAnsE) 158 | - [12.3. Managing Packages with pip](https://youtu.be/vQqisFjAnsE) 159 | 160 | - [13. PEP 8 - Style Guide for Python code](https://youtu.be/vQqisFjAnsE) 161 | 162 | - [13.1. Introduction](https://youtu.be/vQqisFjAnsE) 163 | 164 | - [13.2. A Foolish Consistency is the Hobgoblin of Little Minds](https://youtu.be/vQqisFjAnsE) 165 | 166 | - [13.3. Code Lay-out](https://youtu.be/vQqisFjAnsE) 167 | - [13.3.1. Indentation](https://youtu.be/vQqisFjAnsE) 168 | - [13.3.2. Tabs or Spaces?](https://youtu.be/vQqisFjAnsE) 169 | - [13.3.3. Maximum Line Length](https://youtu.be/vQqisFjAnsE) 170 | - [13.3.4. Should a Line Break Before or After a Binary Operator?](https://youtu.be/vQqisFjAnsE) 171 | - [13.3.5. Blank Lines](https://youtu.be/vQqisFjAnsE) 172 | - [13.3.6. Source File Encoding](https://youtu.be/vQqisFjAnsE) 173 | - [13.3.7. Imports](https://youtu.be/vQqisFjAnsE) 174 | - [13.3.8. Module Level Dunder Names](https://youtu.be/vQqisFjAnsE) 175 | 176 | - [13.4. String Quotes](https://youtu.be/vQqisFjAnsE) 177 | 178 | - [13.5. Whitespace in Expressions and Statements](https://youtu.be/vQqisFjAnsE) 179 | - [13.5.1. Pet Peeves](https://youtu.be/vQqisFjAnsE) 180 | - [13.5.2. Other Recommendations](https://youtu.be/vQqisFjAnsE) 181 | 182 | - [13.6. When to Use Trailing Commas](https://youtu.be/vQqisFjAnsE) 183 | 184 | - [13.7. Comments](https://youtu.be/vQqisFjAnsE) 185 | - [13.7.1. Block Comments](https://youtu.be/vQqisFjAnsE) 186 | - [13.7.2. Inline Comments](https://youtu.be/vQqisFjAnsE) 187 | - [13.7.3. Documentation Strings](https://youtu.be/vQqisFjAnsE) 188 | 189 | - [13.8. Naming Conventions](https://youtu.be/vQqisFjAnsE) 190 | - [13.8.1. Overriding Principle](https://youtu.be/vQqisFjAnsE) 191 | - [13.8.2. Descriptive: Naming Styles](https://youtu.be/vQqisFjAnsE) 192 | - [13.8.3. Prescriptive: Naming Conventions](https://youtu.be/vQqisFjAnsE) 193 | - [13.8.3.1. Names to Avoid](https://youtu.be/vQqisFjAnsE) 194 | - [13.8.3.2. ASCII Compatibility](https://youtu.be/vQqisFjAnsE) 195 | - [13.8.3.3. Package and Module Names](https://youtu.be/vQqisFjAnsE) 196 | - [13.8.3.4. Class Names](https://youtu.be/vQqisFjAnsE) 197 | - [13.8.3.5. Type Variable Names](https://youtu.be/vQqisFjAnsE) 198 | - [13.8.3.6. Exception Names](https://youtu.be/vQqisFjAnsE) 199 | - [13.8.3.7. Global Variable Names](https://youtu.be/vQqisFjAnsE) 200 | - [13.8.3.8. Function and Variable Names](https://youtu.be/vQqisFjAnsE) 201 | - [13.8.3.9. Function and Method Arguments](https://youtu.be/vQqisFjAnsE) 202 | - [13.8.3.10. Method Names and Instance Variables](https://youtu.be/vQqisFjAnsE) 203 | - [13.8.3.11. Constants](https://youtu.be/vQqisFjAnsE) 204 | - [13.8.3.12. Designing for Inheritance](https://youtu.be/vQqisFjAnsE) 205 | - [13.8.4. Public and Internal Interfaces](https://youtu.be/vQqisFjAnsE) 206 | 207 | - [13.9. Programming Recommendations](https://youtu.be/vQqisFjAnsE) 208 | - [13.9.1. Function Annotations](https://youtu.be/vQqisFjAnsE) 209 | - [13.9.2. Variable Annotations](https://youtu.be/vQqisFjAnsE) 210 | 211 | - [14. [BONUS] Google Python Style Guide](https://youtu.be/vQqisFjAnsE) 212 | 213 | - [14.1. Background](https://youtu.be/vQqisFjAnsE) 214 | 215 | - [14.2. Python Language Rules](https://youtu.be/vQqisFjAnsE) 216 | - [14.2.1. Lint](https://youtu.be/vQqisFjAnsE) 217 | - [14.2.2. Imports](https://youtu.be/vQqisFjAnsE) 218 | - [14.2.3. Packages](https://youtu.be/vQqisFjAnsE) 219 | - [14.2.4. Exceptions](https://youtu.be/vQqisFjAnsE) 220 | - [14.2.5. Global variables](https://youtu.be/vQqisFjAnsE) 221 | - [14.2.6. Nested/Local/Inner Classes and Functions](https://youtu.be/vQqisFjAnsE) 222 | - [14.2.7. Comprehensions & Generator Expressions](https://youtu.be/vQqisFjAnsE) 223 | - [14.2.8. Default Iterators and Operators](https://youtu.be/vQqisFjAnsE) 224 | - [14.2.9. Generators](https://youtu.be/vQqisFjAnsE) 225 | - [14.2.10. Lambda Functions](https://youtu.be/vQqisFjAnsE) 226 | - [14.2.11. Conditional Expressions](https://youtu.be/vQqisFjAnsE) 227 | - [14.2.12. Default Argument Values](https://youtu.be/vQqisFjAnsE) 228 | - [14.2.13. Properties](https://youtu.be/vQqisFjAnsE) 229 | - [14.2.14. True/False Evaluations](https://youtu.be/vQqisFjAnsE) 230 | - [14.2.16. Lexical Scoping](https://youtu.be/vQqisFjAnsE) 231 | - [14.2.17. Function and Method Decorators](https://youtu.be/vQqisFjAnsE) 232 | - [14.2.18. Threading](https://youtu.be/vQqisFjAnsE) 233 | - [14.2.19. Power Features](https://youtu.be/vQqisFjAnsE) 234 | - [14.2.20. Modern Python: Python 3 and from \_\_future__ imports](https://youtu.be/vQqisFjAnsE) 235 | - [14.2.21. Type Annotated Code](https://youtu.be/vQqisFjAnsE) 236 | 237 | - [14.3. Python Style Rules](https://youtu.be/vQqisFjAnsE) 238 | - [14.3.1. Semicolons](https://youtu.be/vQqisFjAnsE) 239 | - [14.3.2. Line length](https://youtu.be/vQqisFjAnsE) 240 | - [14.3.3. Parentheses](https://youtu.be/vQqisFjAnsE) 241 | - [14.3.4. Indentation](https://youtu.be/vQqisFjAnsE) 242 | - [14.3.4.1. Trailing commas in sequences of items?](https://youtu.be/vQqisFjAnsE) 243 | - [14.3.5. Blank Lines](https://youtu.be/vQqisFjAnsE) 244 | - [14.3.6. Whitespace](https://youtu.be/vQqisFjAnsE) 245 | - [14.3.7. Shebang Line](https://youtu.be/vQqisFjAnsE) 246 | - [14.3.8. Comments and Docstrings](https://youtu.be/vQqisFjAnsE) 247 | - [14.3.8.1. Docstrings](https://youtu.be/vQqisFjAnsE) 248 | - [14.3.8.2. Modules](https://youtu.be/vQqisFjAnsE) 249 | - [14.3.8.3. Functions and Methods](https://youtu.be/vQqisFjAnsE) 250 | - [14.3.8.4. Classes](https://youtu.be/vQqisFjAnsE) 251 | - [14.3.8.5. Block and Inline Comments](https://youtu.be/vQqisFjAnsE) 252 | - [14.3.8.6. Punctuation, Spelling, and Grammar](https://youtu.be/vQqisFjAnsE) 253 | - [14.3.10. Strings](https://youtu.be/vQqisFjAnsE) 254 | - [14.3.10.1. Logging](https://youtu.be/vQqisFjAnsE) 255 | - [14.3.10.2. Error Messages](https://youtu.be/vQqisFjAnsE) 256 | - [14.3.11. Files and Sockets](https://youtu.be/vQqisFjAnsE) 257 | - [14.3.12. TODO Comments](https://youtu.be/vQqisFjAnsE) 258 | - [14.3.13. Imports formatting](https://youtu.be/vQqisFjAnsE) 259 | - [14.3.14. Statements](https://youtu.be/vQqisFjAnsE) 260 | - [14.3.15. Accessors](https://youtu.be/vQqisFjAnsE) 261 | - [14.3.16. Naming](https://youtu.be/vQqisFjAnsE) 262 | - [14.3.16.1. Names to Avoid](https://youtu.be/vQqisFjAnsE) 263 | - [14.3.16.2. Naming Conventions](https://youtu.be/vQqisFjAnsE) 264 | - [14.3.16.3. File Naming](https://youtu.be/vQqisFjAnsE) 265 | - [14.3.16.4. Guidelines derived from Guido’s Recommendations](https://youtu.be/vQqisFjAnsE) 266 | - [14.3.17. Main](https://youtu.be/vQqisFjAnsE) 267 | - [14.3.18. Function length](https://youtu.be/vQqisFjAnsE) 268 | - [14.3.19. Type Annotations](https://youtu.be/vQqisFjAnsE) 269 | - [14.3.19.1. General Rules](https://youtu.be/vQqisFjAnsE) 270 | - [14.3.19.2. Line Breaking](https://youtu.be/vQqisFjAnsE) 271 | - [14.3.19.3. Forward Declarations](https://youtu.be/vQqisFjAnsE) 272 | - [14.3.19.4. Default Values](https://youtu.be/vQqisFjAnsE) 273 | - [14.3.19.5. NoneType](https://youtu.be/vQqisFjAnsE) 274 | - [14.3.19.6. Type Aliases](https://youtu.be/vQqisFjAnsE) 275 | - [14.3.19.7. Ignoring Types](https://youtu.be/vQqisFjAnsE) 276 | - [14.3.19.8. Typing Variables](https://youtu.be/vQqisFjAnsE) 277 | - [14.3.19.9. Tuples vs Lists](https://youtu.be/vQqisFjAnsE) 278 | - [14.3.19.10. TypeVars](https://youtu.be/vQqisFjAnsE) 279 | - [14.3.19.11. String types](https://youtu.be/vQqisFjAnsE) 280 | - [14.3.19.12. Imports For Typing](https://youtu.be/vQqisFjAnsE) 281 | - [14.3.19.13. Conditional Imports](https://youtu.be/vQqisFjAnsE) 282 | - [14.3.19.14. Circular Dependencies](https://youtu.be/vQqisFjAnsE) 283 | - [14.3.19.15. Generics](https://youtu.be/vQqisFjAnsE) 284 | - [14.3.19.16. Build Dependencies](https://youtu.be/vQqisFjAnsE) 285 | 286 | - [14.4. Parting Words](https://youtu.be/vQqisFjAnsE) 287 | - [15. Python libraries](https://youtu.be/vQqisFjAnsE) 288 | - [16. Python integretions with other technologies](https://youtu.be/vQqisFjAnsE) 289 | - [17. Python Web technologies](https://youtu.be/vQqisFjAnsE) 290 | - [18. Python Machine Learning](https://youtu.be/vQqisFjAnsE) 291 | - [19. Python automation](https://youtu.be/vQqisFjAnsE) 292 | - [20. Python modules](https://youtu.be/vQqisFjAnsE) 293 | - [21. Python coding challenges](https://youtu.be/vQqisFjAnsE) 294 | -------------------------------------------------------------------------------- /Template in Python #1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# [Amin M. Boulouma Blog](https://amboulouma.com)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Template in Python #1" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "> [Reminder] 🔔\n", 22 | "- Help the creator channel reach 20k subscribers. He will keep uploading quality content for you: [Amin M. Boulouma Channel](https://www.youtube.com/channel/UCOZbokHO727qeStxeYSKMUQ?sub_confirmation=1)\n", 23 | "- This tutorial is best understood following the video playlist: [Python Ultimate Tutorial [Official Documentation]](https://www.youtube.com/watch?v=vQqisFjAnsE&list=PLpMTHmi814W0nSToTOC0Q18kREOjcJspW&index=1)" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "Hosted by Amin M. Boulouma, contact and questions: [amine.boulouma.com](https://amine.boulouma.com)\n", 31 | "- Python tutorial made simple: https://youtu.be/vQqisFjAnsE\n", 32 | "- Source code: https://amboulouma.com/python-tutorial\n", 33 | "- Github: https://github.com/amboulouma/python-ultimate-tutorial" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "### Template" 41 | ] 42 | } 43 | ], 44 | "metadata": { 45 | "kernelspec": { 46 | "display_name": "Python 3", 47 | "language": "python", 48 | "name": "python3" 49 | }, 50 | "language_info": { 51 | "codemirror_mode": { 52 | "name": "ipython", 53 | "version": 3 54 | }, 55 | "file_extension": ".py", 56 | "mimetype": "text/x-python", 57 | "name": "python", 58 | "nbconvert_exporter": "python", 59 | "pygments_lexer": "ipython3", 60 | "version": "3.8.5" 61 | } 62 | }, 63 | "nbformat": 4, 64 | "nbformat_minor": 4 65 | } 66 | -------------------------------------------------------------------------------- /Virtual Environments and Packages in Python #14.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# [Amin M. Boulouma Blog](https://amboulouma.com)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Virtual Environments and Packages in Python #14" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "> [Reminder] 🔔\n", 22 | "- Help the creator channel reach 20k subscribers. He will keep uploading quality content for you: [Amin M. Boulouma Channel](https://www.youtube.com/channel/UCOZbokHO727qeStxeYSKMUQ?sub_confirmation=1)\n", 23 | "- This tutorial is best understood following the video playlist: [Python Ultimate Tutorial [Official Documentation]](https://www.youtube.com/watch?v=vQqisFjAnsE&list=PLpMTHmi814W0nSToTOC0Q18kREOjcJspW&index=1)" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "Hosted by Amin M. Boulouma, contact and questions: [amine.boulouma.com](https://amine.boulouma.com)\n", 31 | "- Python tutorial made simple: https://youtu.be/vQqisFjAnsE\n", 32 | "- Source code: https://amboulouma.com/python-tutorial\n", 33 | "- Github: https://github.com/amboulouma/python-ultimate-tutorial" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "### Creating a Python Virtual Environment" 41 | ] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "metadata": {}, 46 | "source": [ 47 | "python3 -m venv tutorial-env" 48 | ] 49 | }, 50 | { 51 | "cell_type": "markdown", 52 | "metadata": {}, 53 | "source": [ 54 | "source tutorial-env/bin/activate" 55 | ] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "metadata": {}, 60 | "source": [ 61 | "### Managing Packages with pip" 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "metadata": {}, 67 | "source": [ 68 | "python -m pip install novas" 69 | ] 70 | }, 71 | { 72 | "cell_type": "markdown", 73 | "metadata": {}, 74 | "source": [ 75 | "python -m pip install requests==2.6.0" 76 | ] 77 | }, 78 | { 79 | "cell_type": "markdown", 80 | "metadata": {}, 81 | "source": [ 82 | "python -m pip install --upgrade requests" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "pip show requests" 90 | ] 91 | }, 92 | { 93 | "cell_type": "markdown", 94 | "metadata": {}, 95 | "source": [ 96 | "pip list" 97 | ] 98 | }, 99 | { 100 | "cell_type": "markdown", 101 | "metadata": {}, 102 | "source": [ 103 | "pip freeze > requirements.txt" 104 | ] 105 | }, 106 | { 107 | "cell_type": "markdown", 108 | "metadata": {}, 109 | "source": [ 110 | "cat requirements.txt" 111 | ] 112 | }, 113 | { 114 | "cell_type": "markdown", 115 | "metadata": {}, 116 | "source": [ 117 | "python -m pip install -r requirements.txt" 118 | ] 119 | } 120 | ], 121 | "metadata": { 122 | "kernelspec": { 123 | "display_name": "Python 3", 124 | "language": "python", 125 | "name": "python3" 126 | }, 127 | "language_info": { 128 | "codemirror_mode": { 129 | "name": "ipython", 130 | "version": 3 131 | }, 132 | "file_extension": ".py", 133 | "mimetype": "text/x-python", 134 | "name": "python", 135 | "nbconvert_exporter": "python", 136 | "pygments_lexer": "ipython3", 137 | "version": "3.8.5" 138 | } 139 | }, 140 | "nbformat": 4, 141 | "nbformat_minor": 4 142 | } 143 | -------------------------------------------------------------------------------- /assets/heap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aminblm/python-ultimate-tutorial/298b388926c426bdf3c09d816b91e60b7db1c391/assets/heap.png -------------------------------------------------------------------------------- /if, for and loop statements in Python #3.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# [Amin M. Boulouma Blog](https://amboulouma.com)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## if, for and loop statements in Python #3" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "> [Reminder] 🔔\n", 22 | "- Help the creator channel reach 20k subscribers. He will keep uploading quality content for you: [Amin M. Boulouma Channel](https://www.youtube.com/channel/UCOZbokHO727qeStxeYSKMUQ?sub_confirmation=1)\n", 23 | "- This tutorial is best understood following the video playlist: [Python Ultimate Tutorial [Official Documentation]](https://www.youtube.com/watch?v=vQqisFjAnsE&list=PLpMTHmi814W0nSToTOC0Q18kREOjcJspW&index=1)" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "Hosted by Amin M. Boulouma, contact and questions: [amine.boulouma.com](https://amine.boulouma.com)\n", 31 | "- Python tutorial made simple: https://youtu.be/vQqisFjAnsE\n", 32 | "- Source code: https://amboulouma.com/python-tutorial\n", 33 | "- Github: https://github.com/amboulouma/python-ultimate-tutorial" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "### if Statements" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 6, 46 | "metadata": {}, 47 | "outputs": [ 48 | { 49 | "name": "stdout", 50 | "output_type": "stream", 51 | "text": [ 52 | "Please enter an integer: 1\n" 53 | ] 54 | } 55 | ], 56 | "source": [ 57 | "x = int(input(\"Please enter an integer: \"))" 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": 7, 63 | "metadata": {}, 64 | "outputs": [ 65 | { 66 | "name": "stdout", 67 | "output_type": "stream", 68 | "text": [ 69 | "Single\n" 70 | ] 71 | } 72 | ], 73 | "source": [ 74 | "if x < 0:\n", 75 | " x = 0\n", 76 | " print('Negative changed to zero')\n", 77 | "elif x == 0: # if ... Else if ... Else\n", 78 | " print('Zero')\n", 79 | "elif x == 1:\n", 80 | " print('Single')\n", 81 | "else:\n", 82 | " print('More')" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "### for Statements" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": 8, 95 | "metadata": {}, 96 | "outputs": [ 97 | { 98 | "name": "stdout", 99 | "output_type": "stream", 100 | "text": [ 101 | "cat 3\n", 102 | "window 6\n", 103 | "defenestrate 12\n" 104 | ] 105 | } 106 | ], 107 | "source": [ 108 | "# Measure some strings:\n", 109 | "words = ['cat', 'window', 'defenestrate']\n", 110 | "for w in words:\n", 111 | " print(w, len(w))" 112 | ] 113 | }, 114 | { 115 | "cell_type": "markdown", 116 | "metadata": {}, 117 | "source": [ 118 | "### The range() Function" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": 9, 124 | "metadata": {}, 125 | "outputs": [ 126 | { 127 | "name": "stdout", 128 | "output_type": "stream", 129 | "text": [ 130 | "0\n", 131 | "1\n", 132 | "2\n", 133 | "3\n", 134 | "4\n" 135 | ] 136 | } 137 | ], 138 | "source": [ 139 | "for i in range(5):\n", 140 | " print(i)" 141 | ] 142 | }, 143 | { 144 | "cell_type": "code", 145 | "execution_count": 13, 146 | "metadata": {}, 147 | "outputs": [ 148 | { 149 | "name": "stdout", 150 | "output_type": "stream", 151 | "text": [ 152 | "0 Mary\n", 153 | "2 a\n", 154 | "4 lamb\n" 155 | ] 156 | } 157 | ], 158 | "source": [ 159 | "a = ['Mary', 'had', 'a', 'little', 'lamb'] # len(a) == 5 ==> range(5)\n", 160 | "for i in range(0, len(a), 2):\n", 161 | " print(i, a[i])" 162 | ] 163 | }, 164 | { 165 | "cell_type": "code", 166 | "execution_count": 15, 167 | "metadata": {}, 168 | "outputs": [ 169 | { 170 | "name": "stdout", 171 | "output_type": "stream", 172 | "text": [ 173 | "range(1, 10, 2)\n" 174 | ] 175 | } 176 | ], 177 | "source": [ 178 | "print(range(1, 10, 2)) #start, end, step" 179 | ] 180 | }, 181 | { 182 | "cell_type": "code", 183 | "execution_count": 16, 184 | "metadata": {}, 185 | "outputs": [ 186 | { 187 | "data": { 188 | "text/plain": [ 189 | "6" 190 | ] 191 | }, 192 | "execution_count": 16, 193 | "metadata": {}, 194 | "output_type": "execute_result" 195 | } 196 | ], 197 | "source": [ 198 | "sum(range(4)) # 0 + 1 + 2 + 3" 199 | ] 200 | }, 201 | { 202 | "cell_type": "code", 203 | "execution_count": 17, 204 | "metadata": {}, 205 | "outputs": [ 206 | { 207 | "data": { 208 | "text/plain": [ 209 | "[0, 1, 2, 3]" 210 | ] 211 | }, 212 | "execution_count": 17, 213 | "metadata": {}, 214 | "output_type": "execute_result" 215 | } 216 | ], 217 | "source": [ 218 | "list(range(4))" 219 | ] 220 | }, 221 | { 222 | "cell_type": "markdown", 223 | "metadata": {}, 224 | "source": [ 225 | "### break and continue Statements, and else Clauses on Loops" 226 | ] 227 | }, 228 | { 229 | "cell_type": "markdown", 230 | "metadata": {}, 231 | "source": [ 232 | "#### Prime number printing" 233 | ] 234 | }, 235 | { 236 | "cell_type": "code", 237 | "execution_count": 18, 238 | "metadata": {}, 239 | "outputs": [ 240 | { 241 | "name": "stdout", 242 | "output_type": "stream", 243 | "text": [ 244 | "2 is a prime number\n", 245 | "3 is a prime number\n", 246 | "4 equals 2 * 2\n", 247 | "5 is a prime number\n", 248 | "6 equals 2 * 3\n", 249 | "7 is a prime number\n", 250 | "8 equals 2 * 4\n", 251 | "9 equals 3 * 3\n" 252 | ] 253 | } 254 | ], 255 | "source": [ 256 | "for n in range(2, 10): # n: 2 ... 10\n", 257 | " for x in range(2, n): # x: 2 ... n\n", 258 | " if n % x == 0: # n = 5, x: 2 ... 5, n%x == 0 means that n is divisble by x\n", 259 | " print(n, 'equals', x, '*', n//x)\n", 260 | " break\n", 261 | " else:\n", 262 | " # loop fell through without finding a factor\n", 263 | " print(n, 'is a prime number')" 264 | ] 265 | }, 266 | { 267 | "cell_type": "code", 268 | "execution_count": 19, 269 | "metadata": {}, 270 | "outputs": [ 271 | { 272 | "name": "stdout", 273 | "output_type": "stream", 274 | "text": [ 275 | "Found an even number 2\n", 276 | "Found an odd number 3\n", 277 | "Found an even number 4\n", 278 | "Found an odd number 5\n", 279 | "Found an even number 6\n", 280 | "Found an odd number 7\n", 281 | "Found an even number 8\n", 282 | "Found an odd number 9\n" 283 | ] 284 | } 285 | ], 286 | "source": [ 287 | "for num in range(2, 10):\n", 288 | " if num % 2 == 0:\n", 289 | " print(\"Found an even number\", num)\n", 290 | " continue # go to the next iteration of the loop, continue executing the loop with the next iteration\n", 291 | " print(\"Found an odd number\", num)" 292 | ] 293 | }, 294 | { 295 | "cell_type": "markdown", 296 | "metadata": {}, 297 | "source": [ 298 | "### pass Statements" 299 | ] 300 | }, 301 | { 302 | "cell_type": "code", 303 | "execution_count": 20, 304 | "metadata": {}, 305 | "outputs": [ 306 | { 307 | "ename": "KeyboardInterrupt", 308 | "evalue": "", 309 | "output_type": "error", 310 | "traceback": [ 311 | "\u001b[0;31m-------------------------\u001b[0m", 312 | "\u001b[0;31mKeyboardInterrupt\u001b[0mTraceback (most recent call last)", 313 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mwhile\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mpass\u001b[0m \u001b[0;31m# Busy-wait for keyboard interrupt (Ctrl+C)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 314 | "\u001b[0;31mKeyboardInterrupt\u001b[0m: " 315 | ] 316 | } 317 | ], 318 | "source": [ 319 | "while True:\n", 320 | " pass # Busy-wait for keyboard interrupt (Ctrl+C)" 321 | ] 322 | }, 323 | { 324 | "cell_type": "code", 325 | "execution_count": 21, 326 | "metadata": {}, 327 | "outputs": [], 328 | "source": [ 329 | "class MyEmptyClass:\n", 330 | " pass" 331 | ] 332 | }, 333 | { 334 | "cell_type": "code", 335 | "execution_count": 22, 336 | "metadata": {}, 337 | "outputs": [], 338 | "source": [ 339 | "def initlog(*args):\n", 340 | " pass # Remember to implement this!" 341 | ] 342 | } 343 | ], 344 | "metadata": { 345 | "kernelspec": { 346 | "display_name": "Python 3", 347 | "language": "python", 348 | "name": "python3" 349 | }, 350 | "language_info": { 351 | "codemirror_mode": { 352 | "name": "ipython", 353 | "version": 3 354 | }, 355 | "file_extension": ".py", 356 | "mimetype": "text/x-python", 357 | "name": "python", 358 | "nbconvert_exporter": "python", 359 | "pygments_lexer": "ipython3", 360 | "version": "3.8.5" 361 | } 362 | }, 363 | "nbformat": 4, 364 | "nbformat_minor": 4 365 | } 366 | -------------------------------------------------------------------------------- /myFile.txt: -------------------------------------------------------------------------------- 1 | This is line 1 of myFile.txt 2 | This is line 2 of myFile.txt 3 | This is line 3 of myFile.txt 4 | This is line 4 of myFile.txt 5 | This is line 5 of myFile.txt 6 | This is line 6 of myFile.txt 7 | This is line 7 of myFile.txt 8 | This is line 8 of myFile.txt 9 | This is line 9 of myFile.txt 10 | This is line 10 of myFile.txt 11 | -------------------------------------------------------------------------------- /myarchive.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aminblm/python-ultimate-tutorial/298b388926c426bdf3c09d816b91e60b7db1c391/myarchive.zip -------------------------------------------------------------------------------- /workfile: -------------------------------------------------------------------------------- 1 | [1, "simple", "list"] -------------------------------------------------------------------------------- /workfile.json: -------------------------------------------------------------------------------- 1 | [1, "simple", "list"] --------------------------------------------------------------------------------