├── .DS_Store ├── 1-Numbers ├── Abhishek_Numbers.ipynb └── Abhishek_Numbers.pdf ├── 2-Strings ├── Abhishek_Strings.ipynb └── Abhishek_Strings.pdf ├── 3-Lists ├── Abhishek_Lists.ipynb └── Abhishek_Lists.pdf ├── 4-Dictionaries ├── .DS_Store ├── Abhishek_Dictionary.ipynb ├── Abhishek_Dictionary.pdf ├── Abhishek_Dictionary_Iterator.ipynb └── Abhishek_Dictionary_Iterator.pdf ├── 6-Statements ├── .DS_Store ├── Abhishek-for Loops.pdf ├── Abhishek-for+Loops.ipynb ├── Abhishek-if, elif, and else Statements.pdf └── Abhishek-if_else_Condition.ipynb ├── 7-Calendar ├── Abhishek_CalenderModule.ipynb └── Abhishek_CalenderModule.pdf ├── 8-OOPs ├── Abhishek_OOPS_Inheritance.ipynb ├── Abhishek_OOPS_Inheritance.pdf ├── Abhishek_OOPs_Methods.ipynb ├── Abhishek_OOPs_Methods.pdf ├── Abhishek_OOPs_memberVariable.ipynb └── Abhishek_OOPs_memberVariable.pdf ├── 9-Sets ├── Abhishek_Sets.ipynb └── Abhishek_Sets.pdf ├── Numpy └── Abhishek - Numpy .ipynb ├── Pandas └── Abhishek - Pandas.ipynb └── README.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analyticsbyte/Python-3-Bootcamp/a2ddcc4e5a3b2e242ad56d75853480e542771b24/.DS_Store -------------------------------------------------------------------------------- /1-Numbers/Abhishek_Numbers.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Basic Arithmetic" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 30, 13 | "metadata": {}, 14 | "outputs": [ 15 | { 16 | "data": { 17 | "text/plain": [ 18 | "3" 19 | ] 20 | }, 21 | "execution_count": 30, 22 | "metadata": {}, 23 | "output_type": "execute_result" 24 | } 25 | ], 26 | "source": [ 27 | "# Addition\n", 28 | "2+1" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 31, 34 | "metadata": {}, 35 | "outputs": [ 36 | { 37 | "data": { 38 | "text/plain": [ 39 | "1" 40 | ] 41 | }, 42 | "execution_count": 31, 43 | "metadata": {}, 44 | "output_type": "execute_result" 45 | } 46 | ], 47 | "source": [ 48 | "# Subtraction\n", 49 | "2-1" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": 32, 55 | "metadata": {}, 56 | "outputs": [ 57 | { 58 | "data": { 59 | "text/plain": [ 60 | "4" 61 | ] 62 | }, 63 | "execution_count": 32, 64 | "metadata": {}, 65 | "output_type": "execute_result" 66 | } 67 | ], 68 | "source": [ 69 | "# Multiplication\n", 70 | "2*2" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": 33, 76 | "metadata": {}, 77 | "outputs": [ 78 | { 79 | "data": { 80 | "text/plain": [ 81 | "1.5" 82 | ] 83 | }, 84 | "execution_count": 33, 85 | "metadata": {}, 86 | "output_type": "execute_result" 87 | } 88 | ], 89 | "source": [ 90 | "# Division\n", 91 | "3/2" 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": 34, 97 | "metadata": {}, 98 | "outputs": [ 99 | { 100 | "data": { 101 | "text/plain": [ 102 | "1" 103 | ] 104 | }, 105 | "execution_count": 34, 106 | "metadata": {}, 107 | "output_type": "execute_result" 108 | } 109 | ], 110 | "source": [ 111 | "# Floor Division\n", 112 | "7//4" 113 | ] 114 | }, 115 | { 116 | "cell_type": "markdown", 117 | "metadata": {}, 118 | "source": [ 119 | "7 divided by 4 equals 1.75 not 1!\n", 120 | "\n", 121 | "The reason we get this result is because we are using \"floor\" division. The // operator (two forward slashes) truncates the decimal without rounding, and returns an integer result." 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": 35, 127 | "metadata": {}, 128 | "outputs": [ 129 | { 130 | "data": { 131 | "text/plain": [ 132 | "3" 133 | ] 134 | }, 135 | "execution_count": 35, 136 | "metadata": {}, 137 | "output_type": "execute_result" 138 | } 139 | ], 140 | "source": [ 141 | "# Modulo\n", 142 | "7%4" 143 | ] 144 | }, 145 | { 146 | "cell_type": "markdown", 147 | "metadata": {}, 148 | "source": [ 149 | "4 goes into 7 once, with a remainder of 3. The % operator returns the remainder after division." 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": 36, 155 | "metadata": {}, 156 | "outputs": [ 157 | { 158 | "data": { 159 | "text/plain": [ 160 | "8" 161 | ] 162 | }, 163 | "execution_count": 36, 164 | "metadata": {}, 165 | "output_type": "execute_result" 166 | } 167 | ], 168 | "source": [ 169 | "# Powers\n", 170 | "2**3" 171 | ] 172 | }, 173 | { 174 | "cell_type": "code", 175 | "execution_count": 37, 176 | "metadata": {}, 177 | "outputs": [ 178 | { 179 | "data": { 180 | "text/plain": [ 181 | "2.0" 182 | ] 183 | }, 184 | "execution_count": 37, 185 | "metadata": {}, 186 | "output_type": "execute_result" 187 | } 188 | ], 189 | "source": [ 190 | "# Can also do roots this way\n", 191 | "4**0.5" 192 | ] 193 | }, 194 | { 195 | "cell_type": "code", 196 | "execution_count": 38, 197 | "metadata": {}, 198 | "outputs": [ 199 | { 200 | "data": { 201 | "text/plain": [ 202 | "105" 203 | ] 204 | }, 205 | "execution_count": 38, 206 | "metadata": {}, 207 | "output_type": "execute_result" 208 | } 209 | ], 210 | "source": [ 211 | "# Order of Operations followed in Python\n", 212 | "2 + 10 * 10 + 3" 213 | ] 214 | }, 215 | { 216 | "cell_type": "code", 217 | "execution_count": 39, 218 | "metadata": {}, 219 | "outputs": [ 220 | { 221 | "data": { 222 | "text/plain": [ 223 | "156" 224 | ] 225 | }, 226 | "execution_count": 39, 227 | "metadata": {}, 228 | "output_type": "execute_result" 229 | } 230 | ], 231 | "source": [ 232 | "# Can use parentheses to specify orders\n", 233 | "(2+10) * (10+3)" 234 | ] 235 | }, 236 | { 237 | "cell_type": "markdown", 238 | "metadata": {}, 239 | "source": [ 240 | "# Variable Assignments" 241 | ] 242 | }, 243 | { 244 | "cell_type": "code", 245 | "execution_count": 40, 246 | "metadata": { 247 | "collapsed": true 248 | }, 249 | "outputs": [], 250 | "source": [ 251 | "# Let's create an object called \"a\" and assign it the number 5\n", 252 | "a = 7" 253 | ] 254 | }, 255 | { 256 | "cell_type": "markdown", 257 | "metadata": {}, 258 | "source": [ 259 | "Now if I call a in my Python script, Python will treat it as the number 7." 260 | ] 261 | }, 262 | { 263 | "cell_type": "code", 264 | "execution_count": 41, 265 | "metadata": {}, 266 | "outputs": [ 267 | { 268 | "data": { 269 | "text/plain": [ 270 | "14" 271 | ] 272 | }, 273 | "execution_count": 41, 274 | "metadata": {}, 275 | "output_type": "execute_result" 276 | } 277 | ], 278 | "source": [ 279 | "# Adding the objects\n", 280 | "a+a" 281 | ] 282 | }, 283 | { 284 | "cell_type": "code", 285 | "execution_count": 42, 286 | "metadata": { 287 | "collapsed": true 288 | }, 289 | "outputs": [], 290 | "source": [ 291 | "# Reassignment\n", 292 | "a = 10" 293 | ] 294 | }, 295 | { 296 | "cell_type": "code", 297 | "execution_count": 43, 298 | "metadata": {}, 299 | "outputs": [ 300 | { 301 | "data": { 302 | "text/plain": [ 303 | "10" 304 | ] 305 | }, 306 | "execution_count": 43, 307 | "metadata": {}, 308 | "output_type": "execute_result" 309 | } 310 | ], 311 | "source": [ 312 | "# Check\n", 313 | "a" 314 | ] 315 | }, 316 | { 317 | "cell_type": "markdown", 318 | "metadata": {}, 319 | "source": [ 320 | "Yes! Python allows you to write over assigned variable names. We can also use the variables themselves when doing the reassignment. Here is an example of what I mean:" 321 | ] 322 | }, 323 | { 324 | "cell_type": "code", 325 | "execution_count": 44, 326 | "metadata": {}, 327 | "outputs": [ 328 | { 329 | "data": { 330 | "text/plain": [ 331 | "10" 332 | ] 333 | }, 334 | "execution_count": 44, 335 | "metadata": {}, 336 | "output_type": "execute_result" 337 | } 338 | ], 339 | "source": [ 340 | "# Check\n", 341 | "a" 342 | ] 343 | }, 344 | { 345 | "cell_type": "code", 346 | "execution_count": 45, 347 | "metadata": { 348 | "collapsed": true 349 | }, 350 | "outputs": [], 351 | "source": [ 352 | "# Use A to redefine A\n", 353 | "a = a + a" 354 | ] 355 | }, 356 | { 357 | "cell_type": "code", 358 | "execution_count": 46, 359 | "metadata": {}, 360 | "outputs": [ 361 | { 362 | "data": { 363 | "text/plain": [ 364 | "20" 365 | ] 366 | }, 367 | "execution_count": 46, 368 | "metadata": {}, 369 | "output_type": "execute_result" 370 | } 371 | ], 372 | "source": [ 373 | "# Check \n", 374 | "a" 375 | ] 376 | }, 377 | { 378 | "cell_type": "markdown", 379 | "metadata": {}, 380 | "source": [ 381 | "The names you use when creating these labels need to follow a few rules:\n", 382 | "\n", 383 | " 1. Names can not start with a number.\n", 384 | " 2. There can be no spaces in the name, use _ instead.\n", 385 | " 3. Can't use any of these symbols :'\",<>/?|\\()!@#$%^&*~-+\n", 386 | " 4. It's considered best practice (PEP8) that names are lowercase.\n", 387 | " 5. Avoid using the characters 'l' (lowercase letter el), 'O' (uppercase letter oh),or 'I' (uppercase letter eye) as single character variable names.\n", 388 | " 6. Avoid using words that have special meaning in Python like \"list\" and \"str\"\n" 389 | ] 390 | }, 391 | { 392 | "cell_type": "markdown", 393 | "metadata": {}, 394 | "source": [ 395 | "# Dynamic Typing" 396 | ] 397 | }, 398 | { 399 | "cell_type": "markdown", 400 | "metadata": {}, 401 | "source": [ 402 | "Python uses dynamic typing, meaning you can reassign variables to different data types. This makes Python very flexible in assigning data types; it differs from other languages that are statically typed." 403 | ] 404 | }, 405 | { 406 | "cell_type": "code", 407 | "execution_count": 47, 408 | "metadata": { 409 | "collapsed": true 410 | }, 411 | "outputs": [], 412 | "source": [ 413 | "my_dogs = 2\n" 414 | ] 415 | }, 416 | { 417 | "cell_type": "code", 418 | "execution_count": 48, 419 | "metadata": {}, 420 | "outputs": [ 421 | { 422 | "data": { 423 | "text/plain": [ 424 | "2" 425 | ] 426 | }, 427 | "execution_count": 48, 428 | "metadata": {}, 429 | "output_type": "execute_result" 430 | } 431 | ], 432 | "source": [ 433 | "my_dogs" 434 | ] 435 | }, 436 | { 437 | "cell_type": "code", 438 | "execution_count": 49, 439 | "metadata": { 440 | "collapsed": true 441 | }, 442 | "outputs": [], 443 | "source": [ 444 | "my_dogs = ['Babon', 'Rolli']" 445 | ] 446 | }, 447 | { 448 | "cell_type": "code", 449 | "execution_count": 50, 450 | "metadata": {}, 451 | "outputs": [ 452 | { 453 | "data": { 454 | "text/plain": [ 455 | "['Babon', 'Rolli']" 456 | ] 457 | }, 458 | "execution_count": 50, 459 | "metadata": {}, 460 | "output_type": "execute_result" 461 | } 462 | ], 463 | "source": [ 464 | "my_dogs" 465 | ] 466 | }, 467 | { 468 | "cell_type": "markdown", 469 | "metadata": {}, 470 | "source": [ 471 | "## Pros and Cons of Dynamic Typing" 472 | ] 473 | }, 474 | { 475 | "cell_type": "markdown", 476 | "metadata": {}, 477 | "source": [ 478 | "### Pros of Dynamic Typing\n", 479 | " - very easy to work with\n", 480 | " - faster development time\n" 481 | ] 482 | }, 483 | { 484 | "cell_type": "markdown", 485 | "metadata": {}, 486 | "source": [ 487 | "### Cons of Dynamic Typing\n", 488 | " - may result in unexpected bugs!\n", 489 | " - you need to be aware of type()" 490 | ] 491 | }, 492 | { 493 | "cell_type": "markdown", 494 | "metadata": {}, 495 | "source": [ 496 | "## Determining variable type with type()" 497 | ] 498 | }, 499 | { 500 | "cell_type": "markdown", 501 | "metadata": {}, 502 | "source": [ 503 | "You can check what type of object is assigned to a variable using Python's built-in type() function. Common data types include:\n", 504 | "\n", 505 | " - __int__ (for integer)\n", 506 | " - __float__\n", 507 | " - __str__ (for string)\n", 508 | " - __list__\n", 509 | " - __tuple__\n", 510 | " - __dict__ (for dictionary)\n", 511 | " - __set__\n", 512 | " - __bool__ (for Boolean True/False)" 513 | ] 514 | }, 515 | { 516 | "cell_type": "code", 517 | "execution_count": 51, 518 | "metadata": {}, 519 | "outputs": [ 520 | { 521 | "data": { 522 | "text/plain": [ 523 | "int" 524 | ] 525 | }, 526 | "execution_count": 51, 527 | "metadata": {}, 528 | "output_type": "execute_result" 529 | } 530 | ], 531 | "source": [ 532 | "type(a)" 533 | ] 534 | }, 535 | { 536 | "cell_type": "code", 537 | "execution_count": 52, 538 | "metadata": { 539 | "collapsed": true 540 | }, 541 | "outputs": [], 542 | "source": [ 543 | "a = [1,2]" 544 | ] 545 | }, 546 | { 547 | "cell_type": "code", 548 | "execution_count": 53, 549 | "metadata": {}, 550 | "outputs": [ 551 | { 552 | "data": { 553 | "text/plain": [ 554 | "list" 555 | ] 556 | }, 557 | "execution_count": 53, 558 | "metadata": {}, 559 | "output_type": "execute_result" 560 | } 561 | ], 562 | "source": [ 563 | "type(a)" 564 | ] 565 | }, 566 | { 567 | "cell_type": "markdown", 568 | "metadata": {}, 569 | "source": [ 570 | "# Simple Exercise\n" 571 | ] 572 | }, 573 | { 574 | "cell_type": "markdown", 575 | "metadata": {}, 576 | "source": [ 577 | "This shows how variables make calculations more readable and easier to follow.\n" 578 | ] 579 | }, 580 | { 581 | "cell_type": "code", 582 | "execution_count": 54, 583 | "metadata": { 584 | "collapsed": true 585 | }, 586 | "outputs": [], 587 | "source": [ 588 | "my_income = 100\n", 589 | "tax_rate = 0.1\n", 590 | "my_taxes = my_income * tax_rate" 591 | ] 592 | }, 593 | { 594 | "cell_type": "code", 595 | "execution_count": 55, 596 | "metadata": {}, 597 | "outputs": [ 598 | { 599 | "data": { 600 | "text/plain": [ 601 | "10.0" 602 | ] 603 | }, 604 | "execution_count": 55, 605 | "metadata": {}, 606 | "output_type": "execute_result" 607 | } 608 | ], 609 | "source": [ 610 | "my_taxes" 611 | ] 612 | } 613 | ], 614 | "metadata": { 615 | "kernelspec": { 616 | "display_name": "Python 3", 617 | "language": "python", 618 | "name": "python3" 619 | }, 620 | "language_info": { 621 | "codemirror_mode": { 622 | "name": "ipython", 623 | "version": 3 624 | }, 625 | "file_extension": ".py", 626 | "mimetype": "text/x-python", 627 | "name": "python", 628 | "nbconvert_exporter": "python", 629 | "pygments_lexer": "ipython3", 630 | "version": "3.6.3" 631 | } 632 | }, 633 | "nbformat": 4, 634 | "nbformat_minor": 2 635 | } 636 | -------------------------------------------------------------------------------- /1-Numbers/Abhishek_Numbers.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analyticsbyte/Python-3-Bootcamp/a2ddcc4e5a3b2e242ad56d75853480e542771b24/1-Numbers/Abhishek_Numbers.pdf -------------------------------------------------------------------------------- /2-Strings/Abhishek_Strings.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Strings" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "Strings are used in Python to record text information, such as names. Strings in Python are actually a *sequence*, which basically means Python keeps track of every element in the string as a sequence. For example, Python understands the string \"hello' to be a sequence of letters in a specific order. This means we will be able to use indexing to grab particular letters (like the first letter, or the last letter).\n" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "## Creating a String\n", 22 | "To create a string in Python you need to use either single quotes or double quotes. For example:" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": 8, 28 | "metadata": {}, 29 | "outputs": [ 30 | { 31 | "data": { 32 | "text/plain": [ 33 | "'hello'" 34 | ] 35 | }, 36 | "execution_count": 8, 37 | "metadata": {}, 38 | "output_type": "execute_result" 39 | } 40 | ], 41 | "source": [ 42 | "# Single word\n", 43 | "'hello'" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": 9, 49 | "metadata": {}, 50 | "outputs": [ 51 | { 52 | "data": { 53 | "text/plain": [ 54 | "'I am Abhishek'" 55 | ] 56 | }, 57 | "execution_count": 9, 58 | "metadata": {}, 59 | "output_type": "execute_result" 60 | } 61 | ], 62 | "source": [ 63 | "# Entire phrase \n", 64 | "'I am Abhishek'" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": 10, 70 | "metadata": {}, 71 | "outputs": [ 72 | { 73 | "data": { 74 | "text/plain": [ 75 | "'I am Abhishek'" 76 | ] 77 | }, 78 | "execution_count": 10, 79 | "metadata": {}, 80 | "output_type": "execute_result" 81 | } 82 | ], 83 | "source": [ 84 | "# We can also use double quote\n", 85 | "\"I am Abhishek\"" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": 11, 91 | "metadata": {}, 92 | "outputs": [ 93 | { 94 | "ename": "SyntaxError", 95 | "evalue": "invalid syntax (, line 2)", 96 | "output_type": "error", 97 | "traceback": [ 98 | "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m2\u001b[0m\n\u001b[0;31m ' I'm Abhishek'\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" 99 | ] 100 | } 101 | ], 102 | "source": [ 103 | "# Be careful with quotes!\n", 104 | "' I'm Abhishek'" 105 | ] 106 | }, 107 | { 108 | "cell_type": "markdown", 109 | "metadata": {}, 110 | "source": [ 111 | "The reason for the error above is because the single quote in I'm stopped the string. You can use combinations of double and single quotes to get the complete statement." 112 | ] 113 | }, 114 | { 115 | "cell_type": "code", 116 | "execution_count": 12, 117 | "metadata": {}, 118 | "outputs": [ 119 | { 120 | "data": { 121 | "text/plain": [ 122 | "\" I'm Abhishek \"" 123 | ] 124 | }, 125 | "execution_count": 12, 126 | "metadata": {}, 127 | "output_type": "execute_result" 128 | } 129 | ], 130 | "source": [ 131 | "\" I'm Abhishek \"" 132 | ] 133 | }, 134 | { 135 | "cell_type": "markdown", 136 | "metadata": {}, 137 | "source": [ 138 | "Now let's learn about printing strings!" 139 | ] 140 | }, 141 | { 142 | "cell_type": "markdown", 143 | "metadata": {}, 144 | "source": [ 145 | "## Printing a String\n", 146 | "\n", 147 | "Using Jupyter notebook with just a string in a cell will automatically output strings, but the correct way to display strings in your output is by using a print function." 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": 13, 153 | "metadata": {}, 154 | "outputs": [ 155 | { 156 | "data": { 157 | "text/plain": [ 158 | "'Hello World'" 159 | ] 160 | }, 161 | "execution_count": 13, 162 | "metadata": {}, 163 | "output_type": "execute_result" 164 | } 165 | ], 166 | "source": [ 167 | "# We can simply declare a string\n", 168 | "'Hello World'" 169 | ] 170 | }, 171 | { 172 | "cell_type": "code", 173 | "execution_count": 14, 174 | "metadata": {}, 175 | "outputs": [ 176 | { 177 | "data": { 178 | "text/plain": [ 179 | "'Hello World 2'" 180 | ] 181 | }, 182 | "execution_count": 14, 183 | "metadata": {}, 184 | "output_type": "execute_result" 185 | } 186 | ], 187 | "source": [ 188 | "# Note that we can't output multiple strings this way\n", 189 | "'Hello World 1'\n", 190 | "'Hello World 2'" 191 | ] 192 | }, 193 | { 194 | "cell_type": "markdown", 195 | "metadata": {}, 196 | "source": [ 197 | "We can use a print statement to print a string." 198 | ] 199 | }, 200 | { 201 | "cell_type": "code", 202 | "execution_count": 15, 203 | "metadata": {}, 204 | "outputs": [ 205 | { 206 | "name": "stdout", 207 | "output_type": "stream", 208 | "text": [ 209 | "Hello World 1\n", 210 | "Hello World 2\n", 211 | "Use \n", 212 | " to print a new line\n", 213 | "\n", 214 | "\n", 215 | "See what I mean?\n" 216 | ] 217 | } 218 | ], 219 | "source": [ 220 | "print('Hello World 1')\n", 221 | "print('Hello World 2')\n", 222 | "print('Use \\n to print a new line')\n", 223 | "print('\\n')\n", 224 | "print('See what I mean?')" 225 | ] 226 | }, 227 | { 228 | "cell_type": "markdown", 229 | "metadata": {}, 230 | "source": [ 231 | "## String Basics" 232 | ] 233 | }, 234 | { 235 | "cell_type": "markdown", 236 | "metadata": {}, 237 | "source": [ 238 | "We can also use a function called len() to check the length of a string!" 239 | ] 240 | }, 241 | { 242 | "cell_type": "code", 243 | "execution_count": 16, 244 | "metadata": {}, 245 | "outputs": [ 246 | { 247 | "data": { 248 | "text/plain": [ 249 | "11" 250 | ] 251 | }, 252 | "execution_count": 16, 253 | "metadata": {}, 254 | "output_type": "execute_result" 255 | } 256 | ], 257 | "source": [ 258 | "len('Hello World')" 259 | ] 260 | }, 261 | { 262 | "cell_type": "markdown", 263 | "metadata": {}, 264 | "source": [ 265 | "** Python's built-in len() function counts all of the characters in the string, including spaces and punctuation." 266 | ] 267 | }, 268 | { 269 | "cell_type": "markdown", 270 | "metadata": {}, 271 | "source": [ 272 | "## String Indexing\n", 273 | "\n", 274 | "In Python, we use brackets [] after an object to call its index. We should also note that indexing starts at 0 for Python. Let's create a new object called s and then walk through a few examples of indexing." 275 | ] 276 | }, 277 | { 278 | "cell_type": "code", 279 | "execution_count": 17, 280 | "metadata": { 281 | "collapsed": true 282 | }, 283 | "outputs": [], 284 | "source": [ 285 | "# Assign s as a string\n", 286 | "s = 'Hello World'" 287 | ] 288 | }, 289 | { 290 | "cell_type": "code", 291 | "execution_count": 18, 292 | "metadata": {}, 293 | "outputs": [ 294 | { 295 | "data": { 296 | "text/plain": [ 297 | "'Hello World'" 298 | ] 299 | }, 300 | "execution_count": 18, 301 | "metadata": {}, 302 | "output_type": "execute_result" 303 | } 304 | ], 305 | "source": [ 306 | "#Check\n", 307 | "s" 308 | ] 309 | }, 310 | { 311 | "cell_type": "code", 312 | "execution_count": 19, 313 | "metadata": {}, 314 | "outputs": [ 315 | { 316 | "name": "stdout", 317 | "output_type": "stream", 318 | "text": [ 319 | "Hello World\n" 320 | ] 321 | } 322 | ], 323 | "source": [ 324 | "# Print the object\n", 325 | "print(s) " 326 | ] 327 | }, 328 | { 329 | "cell_type": "markdown", 330 | "metadata": {}, 331 | "source": [ 332 | "Let's start indexing!" 333 | ] 334 | }, 335 | { 336 | "cell_type": "code", 337 | "execution_count": 20, 338 | "metadata": {}, 339 | "outputs": [ 340 | { 341 | "data": { 342 | "text/plain": [ 343 | "'H'" 344 | ] 345 | }, 346 | "execution_count": 20, 347 | "metadata": {}, 348 | "output_type": "execute_result" 349 | } 350 | ], 351 | "source": [ 352 | "# Show first element (in this case a letter)\n", 353 | "s[0]" 354 | ] 355 | }, 356 | { 357 | "cell_type": "code", 358 | "execution_count": 21, 359 | "metadata": {}, 360 | "outputs": [ 361 | { 362 | "data": { 363 | "text/plain": [ 364 | "'e'" 365 | ] 366 | }, 367 | "execution_count": 21, 368 | "metadata": {}, 369 | "output_type": "execute_result" 370 | } 371 | ], 372 | "source": [ 373 | "s[1]" 374 | ] 375 | }, 376 | { 377 | "cell_type": "code", 378 | "execution_count": 22, 379 | "metadata": {}, 380 | "outputs": [ 381 | { 382 | "data": { 383 | "text/plain": [ 384 | "'l'" 385 | ] 386 | }, 387 | "execution_count": 22, 388 | "metadata": {}, 389 | "output_type": "execute_result" 390 | } 391 | ], 392 | "source": [ 393 | "s[2]" 394 | ] 395 | }, 396 | { 397 | "cell_type": "markdown", 398 | "metadata": {}, 399 | "source": [ 400 | "We can use a : to perform *slicing* which grabs everything up to a designated point. For example:" 401 | ] 402 | }, 403 | { 404 | "cell_type": "code", 405 | "execution_count": 23, 406 | "metadata": {}, 407 | "outputs": [ 408 | { 409 | "data": { 410 | "text/plain": [ 411 | "'ello World'" 412 | ] 413 | }, 414 | "execution_count": 23, 415 | "metadata": {}, 416 | "output_type": "execute_result" 417 | } 418 | ], 419 | "source": [ 420 | "# Grab everything past the first term all the way to the length of s which is len(s)\n", 421 | "s[1:]" 422 | ] 423 | }, 424 | { 425 | "cell_type": "code", 426 | "execution_count": 24, 427 | "metadata": {}, 428 | "outputs": [ 429 | { 430 | "data": { 431 | "text/plain": [ 432 | "'Hello World'" 433 | ] 434 | }, 435 | "execution_count": 24, 436 | "metadata": {}, 437 | "output_type": "execute_result" 438 | } 439 | ], 440 | "source": [ 441 | "# Note that there is no change to the original s\n", 442 | "s" 443 | ] 444 | }, 445 | { 446 | "cell_type": "code", 447 | "execution_count": 25, 448 | "metadata": {}, 449 | "outputs": [ 450 | { 451 | "data": { 452 | "text/plain": [ 453 | "'Hel'" 454 | ] 455 | }, 456 | "execution_count": 25, 457 | "metadata": {}, 458 | "output_type": "execute_result" 459 | } 460 | ], 461 | "source": [ 462 | "# Grab everything UP TO the 3rd index\n", 463 | "s[:3]" 464 | ] 465 | }, 466 | { 467 | "cell_type": "code", 468 | "execution_count": 26, 469 | "metadata": {}, 470 | "outputs": [ 471 | { 472 | "data": { 473 | "text/plain": [ 474 | "'Hello World'" 475 | ] 476 | }, 477 | "execution_count": 26, 478 | "metadata": {}, 479 | "output_type": "execute_result" 480 | } 481 | ], 482 | "source": [ 483 | "#Everything\n", 484 | "s[:]" 485 | ] 486 | }, 487 | { 488 | "cell_type": "markdown", 489 | "metadata": {}, 490 | "source": [ 491 | "We can also use negative indexing to go backwards." 492 | ] 493 | }, 494 | { 495 | "cell_type": "code", 496 | "execution_count": 27, 497 | "metadata": {}, 498 | "outputs": [ 499 | { 500 | "data": { 501 | "text/plain": [ 502 | "'d'" 503 | ] 504 | }, 505 | "execution_count": 27, 506 | "metadata": {}, 507 | "output_type": "execute_result" 508 | } 509 | ], 510 | "source": [ 511 | "# Last letter (one index behind 0 so it loops back around)\n", 512 | "s[-1]" 513 | ] 514 | }, 515 | { 516 | "cell_type": "code", 517 | "execution_count": 28, 518 | "metadata": {}, 519 | "outputs": [ 520 | { 521 | "data": { 522 | "text/plain": [ 523 | "'Hello Worl'" 524 | ] 525 | }, 526 | "execution_count": 28, 527 | "metadata": {}, 528 | "output_type": "execute_result" 529 | } 530 | ], 531 | "source": [ 532 | "# Grab everything but the last letter\n", 533 | "s[:-1]" 534 | ] 535 | }, 536 | { 537 | "cell_type": "markdown", 538 | "metadata": {}, 539 | "source": [ 540 | "We can also use index and slice notation to grab elements of a sequence by a specified step size (the default is 1). For instance we can use two colons in a row and then a number specifying the frequency to grab elements. For example:" 541 | ] 542 | }, 543 | { 544 | "cell_type": "code", 545 | "execution_count": 29, 546 | "metadata": {}, 547 | "outputs": [ 548 | { 549 | "data": { 550 | "text/plain": [ 551 | "'Hello World'" 552 | ] 553 | }, 554 | "execution_count": 29, 555 | "metadata": {}, 556 | "output_type": "execute_result" 557 | } 558 | ], 559 | "source": [ 560 | "# Grab everything, but go in steps size of 1\n", 561 | "s[::1]" 562 | ] 563 | }, 564 | { 565 | "cell_type": "code", 566 | "execution_count": 30, 567 | "metadata": {}, 568 | "outputs": [ 569 | { 570 | "data": { 571 | "text/plain": [ 572 | "'HloWrd'" 573 | ] 574 | }, 575 | "execution_count": 30, 576 | "metadata": {}, 577 | "output_type": "execute_result" 578 | } 579 | ], 580 | "source": [ 581 | "# Grab everything, but go in step sizes of 2\n", 582 | "s[::2]" 583 | ] 584 | }, 585 | { 586 | "cell_type": "code", 587 | "execution_count": 31, 588 | "metadata": {}, 589 | "outputs": [ 590 | { 591 | "data": { 592 | "text/plain": [ 593 | "'dlroW olleH'" 594 | ] 595 | }, 596 | "execution_count": 31, 597 | "metadata": {}, 598 | "output_type": "execute_result" 599 | } 600 | ], 601 | "source": [ 602 | "# We can use this to print a string backwards\n", 603 | "s[::-1]" 604 | ] 605 | }, 606 | { 607 | "cell_type": "markdown", 608 | "metadata": { 609 | "collapsed": true 610 | }, 611 | "source": [ 612 | "## String Properties\n", 613 | "It's important to note that strings have an important property known as *immutability*. This means that once a string is created, the elements within it can not be changed or replaced. For example:" 614 | ] 615 | }, 616 | { 617 | "cell_type": "code", 618 | "execution_count": 32, 619 | "metadata": {}, 620 | "outputs": [ 621 | { 622 | "data": { 623 | "text/plain": [ 624 | "'Hello World'" 625 | ] 626 | }, 627 | "execution_count": 32, 628 | "metadata": {}, 629 | "output_type": "execute_result" 630 | } 631 | ], 632 | "source": [ 633 | "s" 634 | ] 635 | }, 636 | { 637 | "cell_type": "code", 638 | "execution_count": 33, 639 | "metadata": {}, 640 | "outputs": [ 641 | { 642 | "ename": "TypeError", 643 | "evalue": "'str' object does not support item assignment", 644 | "output_type": "error", 645 | "traceback": [ 646 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 647 | "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", 648 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Let's try to change the first letter to 'x'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0ms\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'x'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 649 | "\u001b[0;31mTypeError\u001b[0m: 'str' object does not support item assignment" 650 | ] 651 | } 652 | ], 653 | "source": [ 654 | "# Let's try to change the first letter to 'x'\n", 655 | "s[0] = 'x'" 656 | ] 657 | }, 658 | { 659 | "cell_type": "markdown", 660 | "metadata": {}, 661 | "source": [ 662 | "Notice how the error tells us directly what we can't do, change the item assignment!\n", 663 | "\n", 664 | "Something we *can* do is concatenate strings!" 665 | ] 666 | }, 667 | { 668 | "cell_type": "code", 669 | "execution_count": 34, 670 | "metadata": {}, 671 | "outputs": [ 672 | { 673 | "data": { 674 | "text/plain": [ 675 | "'Hello World'" 676 | ] 677 | }, 678 | "execution_count": 34, 679 | "metadata": {}, 680 | "output_type": "execute_result" 681 | } 682 | ], 683 | "source": [ 684 | "s" 685 | ] 686 | }, 687 | { 688 | "cell_type": "code", 689 | "execution_count": 35, 690 | "metadata": {}, 691 | "outputs": [ 692 | { 693 | "data": { 694 | "text/plain": [ 695 | "'Hello World by Abhishek'" 696 | ] 697 | }, 698 | "execution_count": 35, 699 | "metadata": {}, 700 | "output_type": "execute_result" 701 | } 702 | ], 703 | "source": [ 704 | "# Concatenate strings!\n", 705 | "s + ' by Abhishek'" 706 | ] 707 | }, 708 | { 709 | "cell_type": "code", 710 | "execution_count": 36, 711 | "metadata": { 712 | "collapsed": true 713 | }, 714 | "outputs": [], 715 | "source": [ 716 | "# We can reassign s completely though!\n", 717 | "s = s + ' by Abhishek!'" 718 | ] 719 | }, 720 | { 721 | "cell_type": "code", 722 | "execution_count": 37, 723 | "metadata": {}, 724 | "outputs": [ 725 | { 726 | "name": "stdout", 727 | "output_type": "stream", 728 | "text": [ 729 | "Hello World by Abhishek!\n" 730 | ] 731 | } 732 | ], 733 | "source": [ 734 | "print(s)" 735 | ] 736 | }, 737 | { 738 | "cell_type": "code", 739 | "execution_count": 38, 740 | "metadata": {}, 741 | "outputs": [ 742 | { 743 | "data": { 744 | "text/plain": [ 745 | "'Hello World by Abhishek!'" 746 | ] 747 | }, 748 | "execution_count": 38, 749 | "metadata": {}, 750 | "output_type": "execute_result" 751 | } 752 | ], 753 | "source": [ 754 | "s" 755 | ] 756 | }, 757 | { 758 | "cell_type": "markdown", 759 | "metadata": {}, 760 | "source": [ 761 | "We can use the multiplication symbol to create repetition!" 762 | ] 763 | }, 764 | { 765 | "cell_type": "code", 766 | "execution_count": 39, 767 | "metadata": { 768 | "collapsed": true 769 | }, 770 | "outputs": [], 771 | "source": [ 772 | "letter = 'a'" 773 | ] 774 | }, 775 | { 776 | "cell_type": "code", 777 | "execution_count": 40, 778 | "metadata": {}, 779 | "outputs": [ 780 | { 781 | "data": { 782 | "text/plain": [ 783 | "'aaaaaaaaaa'" 784 | ] 785 | }, 786 | "execution_count": 40, 787 | "metadata": {}, 788 | "output_type": "execute_result" 789 | } 790 | ], 791 | "source": [ 792 | "letter*10" 793 | ] 794 | }, 795 | { 796 | "cell_type": "markdown", 797 | "metadata": {}, 798 | "source": [ 799 | "## Basic Built-in String methods\n", 800 | "\n", 801 | "Objects in Python usually have built-in methods. These methods are functions inside the object that can perform actions or commands on the object itself.\n", 802 | "\n", 803 | "We call methods with a period and then the method name. Methods are in the form:\n", 804 | "\n", 805 | "object.method(parameters)\n", 806 | "\n", 807 | "Where parameters are extra arguments we can pass into the method. Don't worry if the details don't make 100% sense right now. Later on we will be creating our own objects and functions!\n", 808 | "\n", 809 | "Here are some examples of built-in methods in strings:" 810 | ] 811 | }, 812 | { 813 | "cell_type": "code", 814 | "execution_count": 41, 815 | "metadata": {}, 816 | "outputs": [ 817 | { 818 | "data": { 819 | "text/plain": [ 820 | "'Hello World by Abhishek!'" 821 | ] 822 | }, 823 | "execution_count": 41, 824 | "metadata": {}, 825 | "output_type": "execute_result" 826 | } 827 | ], 828 | "source": [ 829 | "s" 830 | ] 831 | }, 832 | { 833 | "cell_type": "code", 834 | "execution_count": 42, 835 | "metadata": {}, 836 | "outputs": [ 837 | { 838 | "data": { 839 | "text/plain": [ 840 | "'HELLO WORLD BY ABHISHEK!'" 841 | ] 842 | }, 843 | "execution_count": 42, 844 | "metadata": {}, 845 | "output_type": "execute_result" 846 | } 847 | ], 848 | "source": [ 849 | "# Upper Case a string\n", 850 | "s.upper()" 851 | ] 852 | }, 853 | { 854 | "cell_type": "code", 855 | "execution_count": 43, 856 | "metadata": {}, 857 | "outputs": [ 858 | { 859 | "data": { 860 | "text/plain": [ 861 | "'hello world by abhishek!'" 862 | ] 863 | }, 864 | "execution_count": 43, 865 | "metadata": {}, 866 | "output_type": "execute_result" 867 | } 868 | ], 869 | "source": [ 870 | "# Lower case\n", 871 | "s.lower()" 872 | ] 873 | }, 874 | { 875 | "cell_type": "code", 876 | "execution_count": 44, 877 | "metadata": {}, 878 | "outputs": [ 879 | { 880 | "data": { 881 | "text/plain": [ 882 | "['Hello', 'World', 'by', 'Abhishek!']" 883 | ] 884 | }, 885 | "execution_count": 44, 886 | "metadata": {}, 887 | "output_type": "execute_result" 888 | } 889 | ], 890 | "source": [ 891 | "# Split a string by blank space (this is the default)\n", 892 | "s.split()" 893 | ] 894 | }, 895 | { 896 | "cell_type": "code", 897 | "execution_count": 45, 898 | "metadata": {}, 899 | "outputs": [ 900 | { 901 | "data": { 902 | "text/plain": [ 903 | "['Hello ', 'orld by Abhishek!']" 904 | ] 905 | }, 906 | "execution_count": 45, 907 | "metadata": {}, 908 | "output_type": "execute_result" 909 | } 910 | ], 911 | "source": [ 912 | "# Split by a specific element (doesn't include the element that was split on)\n", 913 | "s.split('W')" 914 | ] 915 | }, 916 | { 917 | "cell_type": "markdown", 918 | "metadata": {}, 919 | "source": [ 920 | "## Print Formatting\n", 921 | "\n", 922 | "We can use the .format() method to add formatted objects to printed string statements. \n", 923 | "\n", 924 | "The easiest way to show this is through an example:" 925 | ] 926 | }, 927 | { 928 | "cell_type": "code", 929 | "execution_count": 46, 930 | "metadata": {}, 931 | "outputs": [ 932 | { 933 | "data": { 934 | "text/plain": [ 935 | "'Insert another string with curly brackets: The inserted string'" 936 | ] 937 | }, 938 | "execution_count": 46, 939 | "metadata": {}, 940 | "output_type": "execute_result" 941 | } 942 | ], 943 | "source": [ 944 | "'Insert another string with curly brackets: {}'.format('The inserted string')" 945 | ] 946 | } 947 | ], 948 | "metadata": { 949 | "kernelspec": { 950 | "display_name": "Python 3", 951 | "language": "python", 952 | "name": "python3" 953 | }, 954 | "language_info": { 955 | "codemirror_mode": { 956 | "name": "ipython", 957 | "version": 3 958 | }, 959 | "file_extension": ".py", 960 | "mimetype": "text/x-python", 961 | "name": "python", 962 | "nbconvert_exporter": "python", 963 | "pygments_lexer": "ipython3", 964 | "version": "3.6.3" 965 | } 966 | }, 967 | "nbformat": 4, 968 | "nbformat_minor": 1 969 | } 970 | -------------------------------------------------------------------------------- /2-Strings/Abhishek_Strings.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analyticsbyte/Python-3-Bootcamp/a2ddcc4e5a3b2e242ad56d75853480e542771b24/2-Strings/Abhishek_Strings.pdf -------------------------------------------------------------------------------- /3-Lists/Abhishek_Lists.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Lists\n", 8 | "\n", 9 | "Earlier when discussing strings we introduced the concept of a *sequence* in Python. Lists can be thought of the most general version of a *sequence* in Python. Unlike strings, they are mutable, meaning the elements inside a list can be changed!\n", 10 | "\n", 11 | "Let's go ahead and see how we can construct lists!" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 1, 17 | "metadata": { 18 | "collapsed": true 19 | }, 20 | "outputs": [], 21 | "source": [ 22 | "# Assign a list to an variable named my_list\n", 23 | "my_list = [1,2,3]" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "We just created a list of integers, but lists can actually hold different object types. For example:" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 2, 36 | "metadata": { 37 | "collapsed": true 38 | }, 39 | "outputs": [], 40 | "source": [ 41 | "my_list = ['string',23,12.3,'abhi']" 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": {}, 47 | "source": [ 48 | "Just like strings, the len() function will tell you how many items are in the sequence of the list." 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": 3, 54 | "metadata": {}, 55 | "outputs": [ 56 | { 57 | "data": { 58 | "text/plain": [ 59 | "4" 60 | ] 61 | }, 62 | "execution_count": 3, 63 | "metadata": {}, 64 | "output_type": "execute_result" 65 | } 66 | ], 67 | "source": [ 68 | "len(my_list)" 69 | ] 70 | }, 71 | { 72 | "cell_type": "markdown", 73 | "metadata": {}, 74 | "source": [ 75 | "### Indexing and Slicing\n", 76 | "Indexing and slicing work just like in strings. Let's make a new list to remind ourselves of how this works:" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 4, 82 | "metadata": { 83 | "collapsed": true 84 | }, 85 | "outputs": [], 86 | "source": [ 87 | "my_list = ['one','two','three',1,2,3]" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": 5, 93 | "metadata": {}, 94 | "outputs": [ 95 | { 96 | "data": { 97 | "text/plain": [ 98 | "'one'" 99 | ] 100 | }, 101 | "execution_count": 5, 102 | "metadata": {}, 103 | "output_type": "execute_result" 104 | } 105 | ], 106 | "source": [ 107 | "# Grab element at index 0\n", 108 | "my_list[0]" 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": 6, 114 | "metadata": {}, 115 | "outputs": [ 116 | { 117 | "data": { 118 | "text/plain": [ 119 | "['two', 'three', 1, 2, 3]" 120 | ] 121 | }, 122 | "execution_count": 6, 123 | "metadata": {}, 124 | "output_type": "execute_result" 125 | } 126 | ], 127 | "source": [ 128 | "# Grab index 1 and everything past it\n", 129 | "my_list[1:]" 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": 7, 135 | "metadata": {}, 136 | "outputs": [ 137 | { 138 | "data": { 139 | "text/plain": [ 140 | "['one', 'two', 'three']" 141 | ] 142 | }, 143 | "execution_count": 7, 144 | "metadata": {}, 145 | "output_type": "execute_result" 146 | } 147 | ], 148 | "source": [ 149 | "# Grab everything UP TO index 3\n", 150 | "my_list[:3]" 151 | ] 152 | }, 153 | { 154 | "cell_type": "markdown", 155 | "metadata": {}, 156 | "source": [ 157 | "We can also use + to concatenate lists, just like we did for strings." 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": 8, 163 | "metadata": {}, 164 | "outputs": [ 165 | { 166 | "data": { 167 | "text/plain": [ 168 | "['one', 'two', 'three', 1, 2, 3, 'abhi']" 169 | ] 170 | }, 171 | "execution_count": 8, 172 | "metadata": {}, 173 | "output_type": "execute_result" 174 | } 175 | ], 176 | "source": [ 177 | "my_list + ['abhi']" 178 | ] 179 | }, 180 | { 181 | "cell_type": "markdown", 182 | "metadata": {}, 183 | "source": [ 184 | "Note: This doesn't actually change the original list!" 185 | ] 186 | }, 187 | { 188 | "cell_type": "code", 189 | "execution_count": 9, 190 | "metadata": {}, 191 | "outputs": [ 192 | { 193 | "data": { 194 | "text/plain": [ 195 | "['one', 'two', 'three', 1, 2, 3]" 196 | ] 197 | }, 198 | "execution_count": 9, 199 | "metadata": {}, 200 | "output_type": "execute_result" 201 | } 202 | ], 203 | "source": [ 204 | "my_list" 205 | ] 206 | }, 207 | { 208 | "cell_type": "markdown", 209 | "metadata": {}, 210 | "source": [ 211 | "You would have to reassign the list to make the change permanent." 212 | ] 213 | }, 214 | { 215 | "cell_type": "code", 216 | "execution_count": 10, 217 | "metadata": { 218 | "collapsed": true 219 | }, 220 | "outputs": [], 221 | "source": [ 222 | "# Reassign\n", 223 | "my_list = my_list + ['abhishek']" 224 | ] 225 | }, 226 | { 227 | "cell_type": "code", 228 | "execution_count": 11, 229 | "metadata": {}, 230 | "outputs": [ 231 | { 232 | "data": { 233 | "text/plain": [ 234 | "['one', 'two', 'three', 1, 2, 3, 'abhishek']" 235 | ] 236 | }, 237 | "execution_count": 11, 238 | "metadata": {}, 239 | "output_type": "execute_result" 240 | } 241 | ], 242 | "source": [ 243 | "my_list" 244 | ] 245 | }, 246 | { 247 | "cell_type": "markdown", 248 | "metadata": {}, 249 | "source": [ 250 | "We can also use the * for a duplication method similar to strings:" 251 | ] 252 | }, 253 | { 254 | "cell_type": "code", 255 | "execution_count": 12, 256 | "metadata": {}, 257 | "outputs": [ 258 | { 259 | "data": { 260 | "text/plain": [ 261 | "['one',\n", 262 | " 'two',\n", 263 | " 'three',\n", 264 | " 1,\n", 265 | " 2,\n", 266 | " 3,\n", 267 | " 'abhishek',\n", 268 | " 'one',\n", 269 | " 'two',\n", 270 | " 'three',\n", 271 | " 1,\n", 272 | " 2,\n", 273 | " 3,\n", 274 | " 'abhishek']" 275 | ] 276 | }, 277 | "execution_count": 12, 278 | "metadata": {}, 279 | "output_type": "execute_result" 280 | } 281 | ], 282 | "source": [ 283 | "# Make the list double\n", 284 | "my_list * 2" 285 | ] 286 | }, 287 | { 288 | "cell_type": "code", 289 | "execution_count": 13, 290 | "metadata": {}, 291 | "outputs": [ 292 | { 293 | "data": { 294 | "text/plain": [ 295 | "['one', 'two', 'three', 1, 2, 3, 'abhishek']" 296 | ] 297 | }, 298 | "execution_count": 13, 299 | "metadata": {}, 300 | "output_type": "execute_result" 301 | } 302 | ], 303 | "source": [ 304 | "# Again doubling not permanent\n", 305 | "my_list" 306 | ] 307 | }, 308 | { 309 | "cell_type": "markdown", 310 | "metadata": {}, 311 | "source": [ 312 | "## Basic List Methods\n", 313 | "\n", 314 | "Lists in Python however, tend to be more flexible than arrays in other languages for a two good reasons: they have no fixed size (meaning we don't have to specify how big a list will be), and they have no fixed type constraint (like we've seen above).\n", 315 | "\n", 316 | "Let's go ahead and explore some more special methods for lists:" 317 | ] 318 | }, 319 | { 320 | "cell_type": "code", 321 | "execution_count": 14, 322 | "metadata": { 323 | "collapsed": true 324 | }, 325 | "outputs": [], 326 | "source": [ 327 | "# Create a new list\n", 328 | "list1 = [1,2,3]" 329 | ] 330 | }, 331 | { 332 | "cell_type": "markdown", 333 | "metadata": {}, 334 | "source": [ 335 | "Use the **append** method to permanently add an item to the end of a list:" 336 | ] 337 | }, 338 | { 339 | "cell_type": "code", 340 | "execution_count": 15, 341 | "metadata": { 342 | "collapsed": true 343 | }, 344 | "outputs": [], 345 | "source": [ 346 | "# Append\n", 347 | "list1.append('append me!')" 348 | ] 349 | }, 350 | { 351 | "cell_type": "code", 352 | "execution_count": 16, 353 | "metadata": {}, 354 | "outputs": [ 355 | { 356 | "data": { 357 | "text/plain": [ 358 | "[1, 2, 3, 'append me!']" 359 | ] 360 | }, 361 | "execution_count": 16, 362 | "metadata": {}, 363 | "output_type": "execute_result" 364 | } 365 | ], 366 | "source": [ 367 | "# Show\n", 368 | "list1" 369 | ] 370 | }, 371 | { 372 | "cell_type": "markdown", 373 | "metadata": {}, 374 | "source": [ 375 | "Use **pop** to \"pop off\" an item from the list. By default pop takes off the last index, but you can also specify which index to pop off. Let's see an example:" 376 | ] 377 | }, 378 | { 379 | "cell_type": "code", 380 | "execution_count": 17, 381 | "metadata": {}, 382 | "outputs": [ 383 | { 384 | "data": { 385 | "text/plain": [ 386 | "1" 387 | ] 388 | }, 389 | "execution_count": 17, 390 | "metadata": {}, 391 | "output_type": "execute_result" 392 | } 393 | ], 394 | "source": [ 395 | "# Pop off the 0 indexed item\n", 396 | "list1.pop(0)" 397 | ] 398 | }, 399 | { 400 | "cell_type": "code", 401 | "execution_count": 18, 402 | "metadata": {}, 403 | "outputs": [ 404 | { 405 | "data": { 406 | "text/plain": [ 407 | "[2, 3, 'append me!']" 408 | ] 409 | }, 410 | "execution_count": 18, 411 | "metadata": {}, 412 | "output_type": "execute_result" 413 | } 414 | ], 415 | "source": [ 416 | "# Show\n", 417 | "list1" 418 | ] 419 | }, 420 | { 421 | "cell_type": "code", 422 | "execution_count": 19, 423 | "metadata": { 424 | "collapsed": true 425 | }, 426 | "outputs": [], 427 | "source": [ 428 | "# Assign the popped element, remember default popped index is -1\n", 429 | "popped_item = list1.pop()" 430 | ] 431 | }, 432 | { 433 | "cell_type": "code", 434 | "execution_count": 20, 435 | "metadata": {}, 436 | "outputs": [ 437 | { 438 | "data": { 439 | "text/plain": [ 440 | "'append me!'" 441 | ] 442 | }, 443 | "execution_count": 20, 444 | "metadata": {}, 445 | "output_type": "execute_result" 446 | } 447 | ], 448 | "source": [ 449 | "popped_item" 450 | ] 451 | }, 452 | { 453 | "cell_type": "code", 454 | "execution_count": 21, 455 | "metadata": {}, 456 | "outputs": [ 457 | { 458 | "data": { 459 | "text/plain": [ 460 | "[2, 3]" 461 | ] 462 | }, 463 | "execution_count": 21, 464 | "metadata": {}, 465 | "output_type": "execute_result" 466 | } 467 | ], 468 | "source": [ 469 | "# Show remaining list\n", 470 | "list1" 471 | ] 472 | }, 473 | { 474 | "cell_type": "markdown", 475 | "metadata": {}, 476 | "source": [ 477 | "It should also be noted that lists indexing will return an error if there is no element at that index. For example:" 478 | ] 479 | }, 480 | { 481 | "cell_type": "code", 482 | "execution_count": 22, 483 | "metadata": {}, 484 | "outputs": [ 485 | { 486 | "ename": "IndexError", 487 | "evalue": "list index out of range", 488 | "output_type": "error", 489 | "traceback": [ 490 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 491 | "\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)", 492 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mlist1\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m100\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 493 | "\u001b[0;31mIndexError\u001b[0m: list index out of range" 494 | ] 495 | } 496 | ], 497 | "source": [ 498 | "list1[100]" 499 | ] 500 | }, 501 | { 502 | "cell_type": "markdown", 503 | "metadata": {}, 504 | "source": [ 505 | "We can use the **sort** method and the **reverse** methods to also effect your lists:" 506 | ] 507 | }, 508 | { 509 | "cell_type": "code", 510 | "execution_count": 23, 511 | "metadata": { 512 | "collapsed": true 513 | }, 514 | "outputs": [], 515 | "source": [ 516 | "new_list = ['a','b','h','i']" 517 | ] 518 | }, 519 | { 520 | "cell_type": "code", 521 | "execution_count": 24, 522 | "metadata": {}, 523 | "outputs": [ 524 | { 525 | "data": { 526 | "text/plain": [ 527 | "['a', 'b', 'h', 'i']" 528 | ] 529 | }, 530 | "execution_count": 24, 531 | "metadata": {}, 532 | "output_type": "execute_result" 533 | } 534 | ], 535 | "source": [ 536 | "#Show\n", 537 | "new_list" 538 | ] 539 | }, 540 | { 541 | "cell_type": "code", 542 | "execution_count": 25, 543 | "metadata": { 544 | "collapsed": true 545 | }, 546 | "outputs": [], 547 | "source": [ 548 | "# Use reverse to reverse order (this is permanent!)\n", 549 | "new_list.reverse()" 550 | ] 551 | }, 552 | { 553 | "cell_type": "code", 554 | "execution_count": 26, 555 | "metadata": {}, 556 | "outputs": [ 557 | { 558 | "data": { 559 | "text/plain": [ 560 | "['i', 'h', 'b', 'a']" 561 | ] 562 | }, 563 | "execution_count": 26, 564 | "metadata": {}, 565 | "output_type": "execute_result" 566 | } 567 | ], 568 | "source": [ 569 | "new_list" 570 | ] 571 | }, 572 | { 573 | "cell_type": "code", 574 | "execution_count": 27, 575 | "metadata": { 576 | "collapsed": true 577 | }, 578 | "outputs": [], 579 | "source": [ 580 | "# Use sort to sort the list (in this case alphabetical order, but for numbers it will go ascending)\n", 581 | "new_list.sort()" 582 | ] 583 | }, 584 | { 585 | "cell_type": "code", 586 | "execution_count": 28, 587 | "metadata": {}, 588 | "outputs": [ 589 | { 590 | "data": { 591 | "text/plain": [ 592 | "['a', 'b', 'h', 'i']" 593 | ] 594 | }, 595 | "execution_count": 28, 596 | "metadata": {}, 597 | "output_type": "execute_result" 598 | } 599 | ], 600 | "source": [ 601 | "new_list" 602 | ] 603 | }, 604 | { 605 | "cell_type": "markdown", 606 | "metadata": {}, 607 | "source": [ 608 | "## Nesting Lists\n", 609 | "A great feature of of Python data structures is that they support *nesting*. This means we can have data structures within data structures. For example: A list inside a list.\n", 610 | "\n", 611 | "Let's see how this works!" 612 | ] 613 | }, 614 | { 615 | "cell_type": "code", 616 | "execution_count": 29, 617 | "metadata": { 618 | "collapsed": true 619 | }, 620 | "outputs": [], 621 | "source": [ 622 | "# Let's make three lists\n", 623 | "lst_1=[1,2,3]\n", 624 | "lst_2=[4,5,6]\n", 625 | "lst_3=[7,8,9]\n", 626 | "\n", 627 | "# Make a list of lists to form a matrix\n", 628 | "matrix = [lst_1,lst_2,lst_3]" 629 | ] 630 | }, 631 | { 632 | "cell_type": "code", 633 | "execution_count": 30, 634 | "metadata": {}, 635 | "outputs": [ 636 | { 637 | "data": { 638 | "text/plain": [ 639 | "[[1, 2, 3], [4, 5, 6], [7, 8, 9]]" 640 | ] 641 | }, 642 | "execution_count": 30, 643 | "metadata": {}, 644 | "output_type": "execute_result" 645 | } 646 | ], 647 | "source": [ 648 | "# Show\n", 649 | "matrix" 650 | ] 651 | }, 652 | { 653 | "cell_type": "markdown", 654 | "metadata": {}, 655 | "source": [ 656 | "We can again use indexing to grab elements, but now there are two levels for the index. The items in the matrix object, and then the items inside that list!" 657 | ] 658 | }, 659 | { 660 | "cell_type": "code", 661 | "execution_count": 31, 662 | "metadata": {}, 663 | "outputs": [ 664 | { 665 | "data": { 666 | "text/plain": [ 667 | "[1, 2, 3]" 668 | ] 669 | }, 670 | "execution_count": 31, 671 | "metadata": {}, 672 | "output_type": "execute_result" 673 | } 674 | ], 675 | "source": [ 676 | "# Grab first item in matrix object\n", 677 | "matrix[0]" 678 | ] 679 | }, 680 | { 681 | "cell_type": "code", 682 | "execution_count": 32, 683 | "metadata": {}, 684 | "outputs": [ 685 | { 686 | "data": { 687 | "text/plain": [ 688 | "1" 689 | ] 690 | }, 691 | "execution_count": 32, 692 | "metadata": {}, 693 | "output_type": "execute_result" 694 | } 695 | ], 696 | "source": [ 697 | "# Grab first item of the first item in the matrix object\n", 698 | "matrix[0][0]" 699 | ] 700 | } 701 | ], 702 | "metadata": { 703 | "kernelspec": { 704 | "display_name": "Python 3", 705 | "language": "python", 706 | "name": "python3" 707 | }, 708 | "language_info": { 709 | "codemirror_mode": { 710 | "name": "ipython", 711 | "version": 3 712 | }, 713 | "file_extension": ".py", 714 | "mimetype": "text/x-python", 715 | "name": "python", 716 | "nbconvert_exporter": "python", 717 | "pygments_lexer": "ipython3", 718 | "version": "3.6.3" 719 | } 720 | }, 721 | "nbformat": 4, 722 | "nbformat_minor": 1 723 | } 724 | -------------------------------------------------------------------------------- /3-Lists/Abhishek_Lists.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analyticsbyte/Python-3-Bootcamp/a2ddcc4e5a3b2e242ad56d75853480e542771b24/3-Lists/Abhishek_Lists.pdf -------------------------------------------------------------------------------- /4-Dictionaries/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analyticsbyte/Python-3-Bootcamp/a2ddcc4e5a3b2e242ad56d75853480e542771b24/4-Dictionaries/.DS_Store -------------------------------------------------------------------------------- /4-Dictionaries/Abhishek_Dictionary.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Create a dictionary" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 6, 13 | "metadata": { 14 | "collapsed": true 15 | }, 16 | "outputs": [], 17 | "source": [ 18 | "#creating dictionary with string values\n", 19 | "#Its a combination of keys and values\n", 20 | "\n", 21 | "my_dict={\"key1\":\"abc\",\"key2\":\"xyz\"} # my_dict is a dictionary where \n", 22 | " # Keys = 'key1' and 'key2'\n", 23 | " # Values = 'abc' and ''" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 7, 29 | "metadata": {}, 30 | "outputs": [ 31 | { 32 | "data": { 33 | "text/plain": [ 34 | "'xyz'" 35 | ] 36 | }, 37 | "execution_count": 7, 38 | "metadata": {}, 39 | "output_type": "execute_result" 40 | } 41 | ], 42 | "source": [ 43 | "my_dict['key2'] # Retrieve values with the help of keys" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": 8, 49 | "metadata": {}, 50 | "outputs": [ 51 | { 52 | "data": { 53 | "text/plain": [ 54 | "{'key1': 'abc', 'key2': 'xyz'}" 55 | ] 56 | }, 57 | "execution_count": 8, 58 | "metadata": {}, 59 | "output_type": "execute_result" 60 | } 61 | ], 62 | "source": [ 63 | "my_dict" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 1, 69 | "metadata": { 70 | "collapsed": true 71 | }, 72 | "outputs": [], 73 | "source": [ 74 | "d1={\"key1\":'abc',\"key2\":123,'key3':['a','b','c']} # Dictionary combination of values like\n", 75 | " # string, integer, list" 76 | ] 77 | }, 78 | { 79 | "cell_type": "markdown", 80 | "metadata": {}, 81 | "source": [ 82 | "# Access list ( key3 ) in dictionary d1 and show 'b' in uppercase" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "we can achieve this in two ways:: \n", 90 | " 1) create variables and assign\n", 91 | " 2) Execute in single statement" 92 | ] 93 | }, 94 | { 95 | "cell_type": "markdown", 96 | "metadata": {}, 97 | "source": [ 98 | "1) create variables and assign " 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": 5, 104 | "metadata": {}, 105 | "outputs": [ 106 | { 107 | "name": "stdout", 108 | "output_type": "stream", 109 | "text": [ 110 | "['a', 'b', 'c']\n" 111 | ] 112 | } 113 | ], 114 | "source": [ 115 | "l=d1['key3']\n", 116 | "print(l)" 117 | ] 118 | }, 119 | { 120 | "cell_type": "code", 121 | "execution_count": 7, 122 | "metadata": {}, 123 | "outputs": [], 124 | "source": [ 125 | "k= l[1] # assign list value to k i.e b" 126 | ] 127 | }, 128 | { 129 | "cell_type": "code", 130 | "execution_count": 9, 131 | "metadata": {}, 132 | "outputs": [ 133 | { 134 | "data": { 135 | "text/plain": [ 136 | "'B'" 137 | ] 138 | }, 139 | "execution_count": 9, 140 | "metadata": {}, 141 | "output_type": "execute_result" 142 | } 143 | ], 144 | "source": [ 145 | "k.upper() # show the value in upper case" 146 | ] 147 | }, 148 | { 149 | "cell_type": "markdown", 150 | "metadata": {}, 151 | "source": [ 152 | "2) Execute it in a single statement" 153 | ] 154 | }, 155 | { 156 | "cell_type": "code", 157 | "execution_count": 2, 158 | "metadata": {}, 159 | "outputs": [ 160 | { 161 | "data": { 162 | "text/plain": [ 163 | "'B'" 164 | ] 165 | }, 166 | "execution_count": 2, 167 | "metadata": {}, 168 | "output_type": "execute_result" 169 | } 170 | ], 171 | "source": [ 172 | "d1[\"key3\"][1].upper() " 173 | ] 174 | }, 175 | { 176 | "cell_type": "markdown", 177 | "metadata": {}, 178 | "source": [ 179 | "# Show all the keys" 180 | ] 181 | }, 182 | { 183 | "cell_type": "code", 184 | "execution_count": 32, 185 | "metadata": {}, 186 | "outputs": [ 187 | { 188 | "data": { 189 | "text/plain": [ 190 | "dict_keys(['key1', 'key2', 'key3'])" 191 | ] 192 | }, 193 | "execution_count": 32, 194 | "metadata": {}, 195 | "output_type": "execute_result" 196 | } 197 | ], 198 | "source": [ 199 | "d1.keys()" 200 | ] 201 | }, 202 | { 203 | "cell_type": "markdown", 204 | "metadata": {}, 205 | "source": [ 206 | "# Show all the values" 207 | ] 208 | }, 209 | { 210 | "cell_type": "code", 211 | "execution_count": 14, 212 | "metadata": {}, 213 | "outputs": [ 214 | { 215 | "data": { 216 | "text/plain": [ 217 | "dict_values(['abc', 123, ['a', 'b', 'c']])" 218 | ] 219 | }, 220 | "execution_count": 14, 221 | "metadata": {}, 222 | "output_type": "execute_result" 223 | } 224 | ], 225 | "source": [ 226 | "d1.values()" 227 | ] 228 | } 229 | ], 230 | "metadata": { 231 | "kernelspec": { 232 | "display_name": "Python 3", 233 | "language": "python", 234 | "name": "python3" 235 | }, 236 | "language_info": { 237 | "codemirror_mode": { 238 | "name": "ipython", 239 | "version": 3 240 | }, 241 | "file_extension": ".py", 242 | "mimetype": "text/x-python", 243 | "name": "python", 244 | "nbconvert_exporter": "python", 245 | "pygments_lexer": "ipython3", 246 | "version": "3.6.3" 247 | } 248 | }, 249 | "nbformat": 4, 250 | "nbformat_minor": 2 251 | } 252 | -------------------------------------------------------------------------------- /4-Dictionaries/Abhishek_Dictionary.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analyticsbyte/Python-3-Bootcamp/a2ddcc4e5a3b2e242ad56d75853480e542771b24/4-Dictionaries/Abhishek_Dictionary.pdf -------------------------------------------------------------------------------- /4-Dictionaries/Abhishek_Dictionary_Iterator.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Show keys and values together ::" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 1, 13 | "metadata": { 14 | "collapsed": true 15 | }, 16 | "outputs": [], 17 | "source": [ 18 | "d ={'k1':1,'k2':2,'k3':3}" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": 2, 24 | "metadata": {}, 25 | "outputs": [ 26 | { 27 | "name": "stdout", 28 | "output_type": "stream", 29 | "text": [ 30 | "k1\n", 31 | "k2\n", 32 | "k3\n" 33 | ] 34 | } 35 | ], 36 | "source": [ 37 | "for i in d:\n", 38 | " print(i) # It will only print keys not values" 39 | ] 40 | }, 41 | { 42 | "cell_type": "markdown", 43 | "metadata": {}, 44 | "source": [ 45 | "# Dictionary iterators" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": 4, 51 | "metadata": {}, 52 | "outputs": [ 53 | { 54 | "name": "stdout", 55 | "output_type": "stream", 56 | "text": [ 57 | "k1\n", 58 | "1\n", 59 | "k2\n", 60 | "2\n", 61 | "k3\n", 62 | "3\n" 63 | ] 64 | } 65 | ], 66 | "source": [ 67 | "for k,v in d.items(): \n", 68 | " print(k)\n", 69 | " print(v)" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 5, 75 | "metadata": { 76 | "collapsed": true 77 | }, 78 | "outputs": [], 79 | "source": [ 80 | "def add_num(num1,num2): \n", 81 | " return num1+num2" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 1, 87 | "metadata": {}, 88 | "outputs": [ 89 | { 90 | "name": "stdout", 91 | "output_type": "stream", 92 | "text": [ 93 | "John\n", 94 | "27\n", 95 | "Male\n" 96 | ] 97 | } 98 | ], 99 | "source": [ 100 | "people = {1: {'name': 'John', 'age': '27', 'sex': 'Male'},\n", 101 | " 2: {'name': 'Marie', 'age': '22', 'sex': 'Female'}}\n", 102 | "\n", 103 | "print(people[1]['name'])\n", 104 | "print(people[1]['age'])\n", 105 | "print(people[1]['sex'])" 106 | ] 107 | }, 108 | { 109 | "cell_type": "markdown", 110 | "metadata": {}, 111 | "source": [ 112 | "# Insert items in dictionary" 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": 2, 118 | "metadata": {}, 119 | "outputs": [ 120 | { 121 | "name": "stdout", 122 | "output_type": "stream", 123 | "text": [ 124 | "{'name': 'Luna', 'age': '24', 'sex': 'Female', 'married': 'No'}\n" 125 | ] 126 | } 127 | ], 128 | "source": [ 129 | "people = {1: {'name': 'John', 'age': '27', 'sex': 'Male'},\n", 130 | " 2: {'name': 'Marie', 'age': '22', 'sex': 'Female'}}\n", 131 | "\n", 132 | "people[3] = {} \n", 133 | "\n", 134 | "people[3]['name'] = 'Luna'\n", 135 | "people[3]['age'] = '24'\n", 136 | "people[3]['sex'] = 'Female'\n", 137 | "people[3]['married'] = 'No'\n", 138 | "\n", 139 | "print(people[3])" 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": 3, 145 | "metadata": {}, 146 | "outputs": [ 147 | { 148 | "data": { 149 | "text/plain": [ 150 | "{1: {'age': '27', 'name': 'John', 'sex': 'Male'},\n", 151 | " 2: {'age': '22', 'name': 'Marie', 'sex': 'Female'},\n", 152 | " 3: {'age': '24', 'married': 'No', 'name': 'Luna', 'sex': 'Female'}}" 153 | ] 154 | }, 155 | "execution_count": 3, 156 | "metadata": {}, 157 | "output_type": "execute_result" 158 | } 159 | ], 160 | "source": [ 161 | "people" 162 | ] 163 | }, 164 | { 165 | "cell_type": "markdown", 166 | "metadata": {}, 167 | "source": [ 168 | "# Delete any item from Dictionary" 169 | ] 170 | }, 171 | { 172 | "cell_type": "code", 173 | "execution_count": 5, 174 | "metadata": {}, 175 | "outputs": [ 176 | { 177 | "name": "stdout", 178 | "output_type": "stream", 179 | "text": [ 180 | "{'name': 'Luna', 'age': '24', 'sex': 'Female'}\n", 181 | "{'name': 'Peter', 'age': '29', 'sex': 'Male'}\n" 182 | ] 183 | } 184 | ], 185 | "source": [ 186 | "people = {1: {'name': 'John', 'age': '27', 'sex': 'Male'},\n", 187 | " 2: {'name': 'Marie', 'age': '22', 'sex': 'Female'},\n", 188 | " 3: {'name': 'Luna', 'age': '24', 'sex': 'Female', 'married': 'No'},\n", 189 | " 4: {'name': 'Peter', 'age': '29', 'sex': 'Male', 'married': 'Yes'}}\n", 190 | "\n", 191 | "del people[3]['married']\n", 192 | "del people[4]['married']\n", 193 | "\n", 194 | "print(people[3])\n", 195 | "print(people[4])" 196 | ] 197 | }, 198 | { 199 | "cell_type": "code", 200 | "execution_count": 6, 201 | "metadata": {}, 202 | "outputs": [ 203 | { 204 | "data": { 205 | "text/plain": [ 206 | "{1: {'age': '27', 'name': 'John', 'sex': 'Male'},\n", 207 | " 2: {'age': '22', 'name': 'Marie', 'sex': 'Female'},\n", 208 | " 3: {'age': '24', 'name': 'Luna', 'sex': 'Female'},\n", 209 | " 4: {'age': '29', 'name': 'Peter', 'sex': 'Male'}}" 210 | ] 211 | }, 212 | "execution_count": 6, 213 | "metadata": {}, 214 | "output_type": "execute_result" 215 | } 216 | ], 217 | "source": [ 218 | "people" 219 | ] 220 | }, 221 | { 222 | "cell_type": "code", 223 | "execution_count": 7, 224 | "metadata": { 225 | "collapsed": true 226 | }, 227 | "outputs": [], 228 | "source": [ 229 | "del people[3]['sex'] # delete sex from 3rd row" 230 | ] 231 | }, 232 | { 233 | "cell_type": "code", 234 | "execution_count": 8, 235 | "metadata": {}, 236 | "outputs": [ 237 | { 238 | "data": { 239 | "text/plain": [ 240 | "{1: {'age': '27', 'name': 'John', 'sex': 'Male'},\n", 241 | " 2: {'age': '22', 'name': 'Marie', 'sex': 'Female'},\n", 242 | " 3: {'age': '24', 'name': 'Luna'},\n", 243 | " 4: {'age': '29', 'name': 'Peter', 'sex': 'Male'}}" 244 | ] 245 | }, 246 | "execution_count": 8, 247 | "metadata": {}, 248 | "output_type": "execute_result" 249 | } 250 | ], 251 | "source": [ 252 | "people" 253 | ] 254 | }, 255 | { 256 | "cell_type": "markdown", 257 | "metadata": {}, 258 | "source": [ 259 | "\n", 260 | "\n", 261 | "# Display different items in dictionary (Nested Dictionary) with proper format" 262 | ] 263 | }, 264 | { 265 | "cell_type": "code", 266 | "execution_count": 6, 267 | "metadata": {}, 268 | "outputs": [ 269 | { 270 | "name": "stdout", 271 | "output_type": "stream", 272 | "text": [ 273 | "\n", 274 | "Person ID: 1\n", 275 | "Name: John\n", 276 | "Age: 27\n", 277 | "Sex: Male\n", 278 | "\n", 279 | "Person ID: 2\n", 280 | "Name: Marie\n", 281 | "Age: 22\n", 282 | "Sex: Female\n" 283 | ] 284 | } 285 | ], 286 | "source": [ 287 | "people = {1: {'Name': 'John', 'Age': '27', 'Sex': 'Male'},\n", 288 | " 2: {'Name': 'Marie', 'Age': '22', 'Sex': 'Female'}}\n", 289 | "\n", 290 | "for p_id, p_info in people.items():\n", 291 | " print(\"\\nPerson ID:\", p_id)\n", 292 | " \n", 293 | " for key in p_info:\n", 294 | " print(key +':', p_info[key])" 295 | ] 296 | } 297 | ], 298 | "metadata": { 299 | "kernelspec": { 300 | "display_name": "Python 3", 301 | "language": "python", 302 | "name": "python3" 303 | }, 304 | "language_info": { 305 | "codemirror_mode": { 306 | "name": "ipython", 307 | "version": 3 308 | }, 309 | "file_extension": ".py", 310 | "mimetype": "text/x-python", 311 | "name": "python", 312 | "nbconvert_exporter": "python", 313 | "pygments_lexer": "ipython3", 314 | "version": "3.6.3" 315 | } 316 | }, 317 | "nbformat": 4, 318 | "nbformat_minor": 2 319 | } 320 | -------------------------------------------------------------------------------- /4-Dictionaries/Abhishek_Dictionary_Iterator.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analyticsbyte/Python-3-Bootcamp/a2ddcc4e5a3b2e242ad56d75853480e542771b24/4-Dictionaries/Abhishek_Dictionary_Iterator.pdf -------------------------------------------------------------------------------- /6-Statements/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analyticsbyte/Python-3-Bootcamp/a2ddcc4e5a3b2e242ad56d75853480e542771b24/6-Statements/.DS_Store -------------------------------------------------------------------------------- /6-Statements/Abhishek-for Loops.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analyticsbyte/Python-3-Bootcamp/a2ddcc4e5a3b2e242ad56d75853480e542771b24/6-Statements/Abhishek-for Loops.pdf -------------------------------------------------------------------------------- /6-Statements/Abhishek-for+Loops.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# for Loops\n", 8 | "\n", 9 | "A for loop acts as an iterator in Python; it goes through items that are in a *sequence* or any other iterable item. Objects that we've learned about that we can iterate over include strings, lists, tuples, and even built-in iterables for dictionaries, such as keys or values.\n", 10 | "\n", 11 | "Here's the general format for a for loop in Python:\n", 12 | "\n", 13 | " for item in object:\n", 14 | " statements to do stuff\n", 15 | " " 16 | ] 17 | }, 18 | { 19 | "cell_type": "code", 20 | "execution_count": 1, 21 | "metadata": { 22 | "collapsed": true 23 | }, 24 | "outputs": [], 25 | "source": [ 26 | "list1 = [1,2,3,4,5,6,7,8,9,10]" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": 2, 32 | "metadata": {}, 33 | "outputs": [ 34 | { 35 | "name": "stdout", 36 | "output_type": "stream", 37 | "text": [ 38 | "1\n", 39 | "2\n", 40 | "3\n", 41 | "4\n", 42 | "5\n", 43 | "6\n", 44 | "7\n", 45 | "8\n", 46 | "9\n", 47 | "10\n" 48 | ] 49 | } 50 | ], 51 | "source": [ 52 | "for num in list1:\n", 53 | " print(num)" 54 | ] 55 | }, 56 | { 57 | "cell_type": "markdown", 58 | "metadata": {}, 59 | "source": [ 60 | "Great! Hopefully this makes sense. Now let's add an if statement to check for __even__ numbers. We'll first introduce a new concept here--the modulo.\n", 61 | "### Modulo\n", 62 | "The modulo allows us to get the remainder in a division and uses the % symbol. For example:" 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": 3, 68 | "metadata": {}, 69 | "outputs": [ 70 | { 71 | "data": { 72 | "text/plain": [ 73 | "3" 74 | ] 75 | }, 76 | "execution_count": 3, 77 | "metadata": {}, 78 | "output_type": "execute_result" 79 | } 80 | ], 81 | "source": [ 82 | "13 % 5" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "This makes sense since 13 divided by 5 is 2 remainder 3. Let's see a few more quick examples:" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": 4, 95 | "metadata": {}, 96 | "outputs": [ 97 | { 98 | "data": { 99 | "text/plain": [ 100 | "1" 101 | ] 102 | }, 103 | "execution_count": 4, 104 | "metadata": {}, 105 | "output_type": "execute_result" 106 | } 107 | ], 108 | "source": [ 109 | "# 3 Remainder 1\n", 110 | "10 % 3" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": 5, 116 | "metadata": {}, 117 | "outputs": [ 118 | { 119 | "data": { 120 | "text/plain": [ 121 | "4" 122 | ] 123 | }, 124 | "execution_count": 5, 125 | "metadata": {}, 126 | "output_type": "execute_result" 127 | } 128 | ], 129 | "source": [ 130 | "# 2 Remainder 4\n", 131 | "18 % 7" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": 6, 137 | "metadata": {}, 138 | "outputs": [ 139 | { 140 | "data": { 141 | "text/plain": [ 142 | "0" 143 | ] 144 | }, 145 | "execution_count": 6, 146 | "metadata": {}, 147 | "output_type": "execute_result" 148 | } 149 | ], 150 | "source": [ 151 | "# 2 no remainder\n", 152 | "4 % 2" 153 | ] 154 | }, 155 | { 156 | "cell_type": "markdown", 157 | "metadata": {}, 158 | "source": [ 159 | "Notice that if a number is fully divisible with no remainder, the result of the modulo call is 0. We can use this to test for even numbers, since if a number modulo 2 is equal to 0, that means it is an even number!\n", 160 | "\n", 161 | "Back to the for loops!\n", 162 | "\n", 163 | "\n", 164 | "### Let's print only the even numbers from that list!" 165 | ] 166 | }, 167 | { 168 | "cell_type": "code", 169 | "execution_count": 7, 170 | "metadata": {}, 171 | "outputs": [ 172 | { 173 | "name": "stdout", 174 | "output_type": "stream", 175 | "text": [ 176 | "2\n", 177 | "4\n", 178 | "6\n", 179 | "8\n", 180 | "10\n" 181 | ] 182 | } 183 | ], 184 | "source": [ 185 | "for num in list1:\n", 186 | " if num % 2 == 0:\n", 187 | " print(num)" 188 | ] 189 | }, 190 | { 191 | "cell_type": "markdown", 192 | "metadata": {}, 193 | "source": [ 194 | "We could have also put an else statement in there:" 195 | ] 196 | }, 197 | { 198 | "cell_type": "code", 199 | "execution_count": 8, 200 | "metadata": {}, 201 | "outputs": [ 202 | { 203 | "name": "stdout", 204 | "output_type": "stream", 205 | "text": [ 206 | "Odd number\n", 207 | "2\n", 208 | "Odd number\n", 209 | "4\n", 210 | "Odd number\n", 211 | "6\n", 212 | "Odd number\n", 213 | "8\n", 214 | "Odd number\n", 215 | "10\n" 216 | ] 217 | } 218 | ], 219 | "source": [ 220 | "for num in list1:\n", 221 | " if num % 2 == 0:\n", 222 | " print(num)\n", 223 | " else:\n", 224 | " print('Odd number')" 225 | ] 226 | }, 227 | { 228 | "cell_type": "markdown", 229 | "metadata": {}, 230 | "source": [ 231 | "### Another common idea during a for loop is keeping some sort of running tally during multiple loops. For example, let's create a for loop that sums up the list:" 232 | ] 233 | }, 234 | { 235 | "cell_type": "code", 236 | "execution_count": 9, 237 | "metadata": {}, 238 | "outputs": [ 239 | { 240 | "name": "stdout", 241 | "output_type": "stream", 242 | "text": [ 243 | "55\n" 244 | ] 245 | } 246 | ], 247 | "source": [ 248 | "# Start sum at zero\n", 249 | "list_sum = 0 \n", 250 | "\n", 251 | "for num in list1:\n", 252 | " list_sum = list_sum + num\n", 253 | "\n", 254 | "print(list_sum)" 255 | ] 256 | }, 257 | { 258 | "cell_type": "markdown", 259 | "metadata": {}, 260 | "source": [ 261 | "Also we could have implemented a += to perform the addition towards the sum. For example:" 262 | ] 263 | }, 264 | { 265 | "cell_type": "code", 266 | "execution_count": 10, 267 | "metadata": {}, 268 | "outputs": [ 269 | { 270 | "name": "stdout", 271 | "output_type": "stream", 272 | "text": [ 273 | "55\n" 274 | ] 275 | } 276 | ], 277 | "source": [ 278 | "# Start sum at zero\n", 279 | "list_sum = 0 \n", 280 | "\n", 281 | "for num in list1:\n", 282 | " list_sum += num\n", 283 | "\n", 284 | "print(list_sum)" 285 | ] 286 | }, 287 | { 288 | "cell_type": "markdown", 289 | "metadata": {}, 290 | "source": [ 291 | "\n", 292 | "### We've used for loops with lists, how about with strings? Remember strings are a sequence so when we iterate through them we will be accessing each item in that string." 293 | ] 294 | }, 295 | { 296 | "cell_type": "code", 297 | "execution_count": 11, 298 | "metadata": {}, 299 | "outputs": [ 300 | { 301 | "name": "stdout", 302 | "output_type": "stream", 303 | "text": [ 304 | "I\n", 305 | " \n", 306 | "a\n", 307 | "m\n", 308 | " \n", 309 | "A\n", 310 | "b\n", 311 | "h\n", 312 | "i\n", 313 | "s\n", 314 | "h\n", 315 | "e\n", 316 | "k\n", 317 | ".\n" 318 | ] 319 | } 320 | ], 321 | "source": [ 322 | "for letter in 'I am Abhishek.':\n", 323 | " print(letter)" 324 | ] 325 | }, 326 | { 327 | "cell_type": "markdown", 328 | "metadata": {}, 329 | "source": [ 330 | "### Let's now look at how a for loop can be used with a tuple:" 331 | ] 332 | }, 333 | { 334 | "cell_type": "code", 335 | "execution_count": 12, 336 | "metadata": {}, 337 | "outputs": [ 338 | { 339 | "name": "stdout", 340 | "output_type": "stream", 341 | "text": [ 342 | "1\n", 343 | "2\n", 344 | "3\n", 345 | "4\n", 346 | "5\n" 347 | ] 348 | } 349 | ], 350 | "source": [ 351 | "tup = (1,2,3,4,5)\n", 352 | "\n", 353 | "for t in tup:\n", 354 | " print(t)" 355 | ] 356 | }, 357 | { 358 | "cell_type": "markdown", 359 | "metadata": {}, 360 | "source": [ 361 | "### Let's start exploring iterating through Dictionaries to explore this further!" 362 | ] 363 | }, 364 | { 365 | "cell_type": "code", 366 | "execution_count": 16, 367 | "metadata": { 368 | "collapsed": true 369 | }, 370 | "outputs": [], 371 | "source": [ 372 | "d = {'k1':1,'k2':2,'k3':3}" 373 | ] 374 | }, 375 | { 376 | "cell_type": "code", 377 | "execution_count": 17, 378 | "metadata": {}, 379 | "outputs": [ 380 | { 381 | "name": "stdout", 382 | "output_type": "stream", 383 | "text": [ 384 | "k1\n", 385 | "k2\n", 386 | "k3\n" 387 | ] 388 | } 389 | ], 390 | "source": [ 391 | "for item in d:\n", 392 | " print(item)" 393 | ] 394 | }, 395 | { 396 | "cell_type": "markdown", 397 | "metadata": {}, 398 | "source": [ 399 | "## Conclusion\n", 400 | "\n", 401 | "We've learned how to use for loops to iterate through tuples, lists, strings, and dictionaries." 402 | ] 403 | }, 404 | { 405 | "cell_type": "code", 406 | "execution_count": null, 407 | "metadata": { 408 | "collapsed": true 409 | }, 410 | "outputs": [], 411 | "source": [] 412 | } 413 | ], 414 | "metadata": { 415 | "kernelspec": { 416 | "display_name": "Python 3", 417 | "language": "python", 418 | "name": "python3" 419 | }, 420 | "language_info": { 421 | "codemirror_mode": { 422 | "name": "ipython", 423 | "version": 3 424 | }, 425 | "file_extension": ".py", 426 | "mimetype": "text/x-python", 427 | "name": "python", 428 | "nbconvert_exporter": "python", 429 | "pygments_lexer": "ipython3", 430 | "version": "3.6.3" 431 | } 432 | }, 433 | "nbformat": 4, 434 | "nbformat_minor": 1 435 | } 436 | -------------------------------------------------------------------------------- /6-Statements/Abhishek-if, elif, and else Statements.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analyticsbyte/Python-3-Bootcamp/a2ddcc4e5a3b2e242ad56d75853480e542771b24/6-Statements/Abhishek-if, elif, and else Statements.pdf -------------------------------------------------------------------------------- /6-Statements/Abhishek-if_else_Condition.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# if, elif, else Statements\n", 8 | "\n", 9 | "if Statements in Python allows us to tell the computer to perform alternative actions based on a certain set of results.\n", 10 | "\n", 11 | "Verbally, we can imagine we are telling the computer:\n", 12 | "\n", 13 | "\"Hey if this case happens, perform some action\"\n", 14 | "\n", 15 | "We can then expand the idea further with elif and else statements, which allow us to tell the computer:\n", 16 | "\n", 17 | "\"Hey if this case happens, perform some action. Else, if another case happens, perform some other action. Else, if *none* of the above cases happened, perform this action.\"\n", 18 | "\n", 19 | "Let's go ahead and look at the syntax format for if statements to get a better idea of this:\n", 20 | "\n", 21 | " if case1:\n", 22 | " perform action1\n", 23 | " elif case2:\n", 24 | " perform action2\n", 25 | " else: \n", 26 | " perform action3" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": 1, 32 | "metadata": {}, 33 | "outputs": [ 34 | { 35 | "name": "stdout", 36 | "output_type": "stream", 37 | "text": [ 38 | "It was true!\n" 39 | ] 40 | } 41 | ], 42 | "source": [ 43 | "if True:\n", 44 | " print('It was true!')" 45 | ] 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "metadata": {}, 50 | "source": [ 51 | "Let's add in some else logic:" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": 2, 57 | "metadata": {}, 58 | "outputs": [ 59 | { 60 | "name": "stdout", 61 | "output_type": "stream", 62 | "text": [ 63 | "x is not true\n" 64 | ] 65 | } 66 | ], 67 | "source": [ 68 | "x = False\n", 69 | "\n", 70 | "if x:\n", 71 | " print('x was True!')\n", 72 | "else:\n", 73 | " print('x is not true')" 74 | ] 75 | }, 76 | { 77 | "cell_type": "markdown", 78 | "metadata": {}, 79 | "source": [ 80 | "### Multiple Branches\n", 81 | "\n", 82 | "Let's get a fuller picture of how far if, elif, and else can take us!\n", 83 | "\n", 84 | "We write this out in a nested structure. Take note of how the if, elif, and else line up in the code. This can help you see what if is related to what elif or else statements.\n" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": 3, 90 | "metadata": {}, 91 | "outputs": [ 92 | { 93 | "name": "stdout", 94 | "output_type": "stream", 95 | "text": [ 96 | "Welcome to Karnataka!\n" 97 | ] 98 | } 99 | ], 100 | "source": [ 101 | "loc = 'Bengaluru'\n", 102 | "\n", 103 | "if loc == 'Kolkata':\n", 104 | " print('Welcome to West Bengal!')\n", 105 | "elif loc == 'Bengaluru':\n", 106 | " print('Welcome to Karnataka!')\n", 107 | "else:\n", 108 | " print('Where are you?')" 109 | ] 110 | }, 111 | { 112 | "cell_type": "markdown", 113 | "metadata": {}, 114 | "source": [ 115 | "Note how the nested if statements are each checked until a True boolean causes the nested code below it to run. You should also note that you can put in as many elif statements as you want before you close off with an else.\n" 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": 4, 121 | "metadata": {}, 122 | "outputs": [ 123 | { 124 | "name": "stdout", 125 | "output_type": "stream", 126 | "text": [ 127 | "Welcome, Abhishek!\n" 128 | ] 129 | } 130 | ], 131 | "source": [ 132 | "person = 'Abhishek'\n", 133 | "\n", 134 | "if person == 'Abhishek':\n", 135 | " print('Welcome, Abhishek!')\n", 136 | "else:\n", 137 | " print(\"Welcome, what's your name?\")" 138 | ] 139 | }, 140 | { 141 | "cell_type": "code", 142 | "execution_count": 5, 143 | "metadata": {}, 144 | "outputs": [ 145 | { 146 | "name": "stdout", 147 | "output_type": "stream", 148 | "text": [ 149 | "Welcome, what's your surname?\n" 150 | ] 151 | } 152 | ], 153 | "source": [ 154 | "person = 'Rajan'\n", 155 | "\n", 156 | "if person == 'Abhishek':\n", 157 | " print('Welcome, Abhishek Sarkar!')\n", 158 | "elif person =='Karan':\n", 159 | " print('Welcome Karan Srivastav!')\n", 160 | "else:\n", 161 | " print(\"Welcome, what's your surname?\")" 162 | ] 163 | }, 164 | { 165 | "cell_type": "markdown", 166 | "metadata": {}, 167 | "source": [ 168 | "## Indentation\n", 169 | "\n", 170 | "It is important to keep a good understanding of how indentation works in Python to maintain the structure and order of your code. We will touch on this topic again when we start building out functions!" 171 | ] 172 | } 173 | ], 174 | "metadata": { 175 | "kernelspec": { 176 | "display_name": "Python 3", 177 | "language": "python", 178 | "name": "python3" 179 | }, 180 | "language_info": { 181 | "codemirror_mode": { 182 | "name": "ipython", 183 | "version": 3 184 | }, 185 | "file_extension": ".py", 186 | "mimetype": "text/x-python", 187 | "name": "python", 188 | "nbconvert_exporter": "python", 189 | "pygments_lexer": "ipython3", 190 | "version": "3.6.3" 191 | } 192 | }, 193 | "nbformat": 4, 194 | "nbformat_minor": 1 195 | } 196 | -------------------------------------------------------------------------------- /7-Calendar/Abhishek_CalenderModule.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 31, 6 | "metadata": { 7 | "collapsed": true 8 | }, 9 | "outputs": [], 10 | "source": [ 11 | "import calendar" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 32, 17 | "metadata": { 18 | "collapsed": true 19 | }, 20 | "outputs": [], 21 | "source": [ 22 | "c=calendar.TextCalendar(calendar.THURSDAY) # tells the interpreter to create a text calendar. \n", 23 | " # Start of the month will be Sunday. In Python, you can format \n", 24 | " # the calendar as you can change the day of the month to begin with" 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": 33, 30 | "metadata": { 31 | "collapsed": true 32 | }, 33 | "outputs": [], 34 | "source": [ 35 | "str = c.formatmonth(2018,3) # creating calendar for the year 2025, Month 1 – January" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 34, 41 | "metadata": { 42 | "scrolled": true 43 | }, 44 | "outputs": [ 45 | { 46 | "name": "stdout", 47 | "output_type": "stream", 48 | "text": [ 49 | " March 2018\n", 50 | "Th Fr Sa Su Mo Tu We\n", 51 | " 1 2 3 4 5 6 7\n", 52 | " 8 9 10 11 12 13 14\n", 53 | "15 16 17 18 19 20 21\n", 54 | "22 23 24 25 26 27 28\n", 55 | "29 30 31\n", 56 | "\n" 57 | ] 58 | } 59 | ], 60 | "source": [ 61 | "print(str)" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": 35, 67 | "metadata": {}, 68 | "outputs": [ 69 | { 70 | "name": "stdout", 71 | "output_type": "stream", 72 | "text": [ 73 | "1\n", 74 | "2\n", 75 | "3\n", 76 | "4\n", 77 | "5\n", 78 | "6\n", 79 | "7\n", 80 | "8\n", 81 | "9\n", 82 | "10\n", 83 | "11\n", 84 | "12\n", 85 | "13\n", 86 | "14\n", 87 | "15\n", 88 | "16\n", 89 | "17\n", 90 | "18\n", 91 | "19\n", 92 | "20\n", 93 | "21\n", 94 | "22\n", 95 | "23\n", 96 | "24\n", 97 | "25\n", 98 | "26\n", 99 | "27\n", 100 | "28\n", 101 | "29\n", 102 | "30\n", 103 | "31\n", 104 | "0\n", 105 | "0\n", 106 | "0\n", 107 | "0\n" 108 | ] 109 | } 110 | ], 111 | "source": [ 112 | "for i in c.itermonthdays(2018,3):\n", 113 | " print(i)\n", 114 | " \n", 115 | " #Zeros in the output mean that the day of the week is in an \n", 116 | " #overlapping month, which means it does not belong to that month.\n", 117 | " \n", 118 | " #These zeros appears in output because, in your code you have mentioned day (Thursday), \n", 119 | " #so when you call function \"c.itermonthdays\" , it will start counting days from Thursday and your Thursday\n", 120 | " #is not necessary to start with date 1st of April it might be 28th or 29th of march, \n", 121 | " #so when you execute the code it will start counting days from 28th of march and any days \n", 122 | " #after that till 1st of April. These days will be counted as zero and in the \n", 123 | " #output you will see these zeroes and same is applicable to the end of the month." 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": 36, 129 | "metadata": {}, 130 | "outputs": [ 131 | { 132 | "name": "stdout", 133 | "output_type": "stream", 134 | "text": [ 135 | "\n", 136 | "January\n", 137 | "February\n", 138 | "March\n", 139 | "April\n", 140 | "May\n", 141 | "June\n", 142 | "July\n", 143 | "August\n", 144 | "September\n", 145 | "October\n", 146 | "November\n", 147 | "December\n" 148 | ] 149 | } 150 | ], 151 | "source": [ 152 | "for i in calendar.month_name:\n", 153 | " print(i)" 154 | ] 155 | }, 156 | { 157 | "cell_type": "code", 158 | "execution_count": 37, 159 | "metadata": {}, 160 | "outputs": [ 161 | { 162 | "name": "stdout", 163 | "output_type": "stream", 164 | "text": [ 165 | "Monday\n", 166 | "Tuesday\n", 167 | "Wednesday\n", 168 | "Thursday\n", 169 | "Friday\n", 170 | "Saturday\n", 171 | "Sunday\n" 172 | ] 173 | } 174 | ], 175 | "source": [ 176 | "for i in calendar.day_name:\n", 177 | " print(i)" 178 | ] 179 | }, 180 | { 181 | "cell_type": "markdown", 182 | "metadata": { 183 | "collapsed": true 184 | }, 185 | "source": [ 186 | "# There is an audit day on every first Monday of a week, and want to know the date for each month of the year, you can use this code" 187 | ] 188 | }, 189 | { 190 | "cell_type": "code", 191 | "execution_count": 38, 192 | "metadata": {}, 193 | "outputs": [ 194 | { 195 | "name": "stdout", 196 | "output_type": "stream", 197 | "text": [ 198 | " January 1\n", 199 | " February 5\n", 200 | " March 5\n", 201 | " April 2\n", 202 | " May 7\n", 203 | " June 4\n", 204 | " July 2\n", 205 | " August 6\n", 206 | " September 3\n", 207 | " October 1\n", 208 | " November 5\n", 209 | " December 3\n" 210 | ] 211 | } 212 | ], 213 | "source": [ 214 | "for month in range (1,13):\n", 215 | " mycal = calendar.monthcalendar(2018,month)\n", 216 | " \n", 217 | " week1=mycal[0]\n", 218 | " week2=mycal[1]\n", 219 | " \n", 220 | " if week1[calendar.MONDAY] != 0:\n", 221 | " auditday = week1[calendar.MONDAY]\n", 222 | " else:\n", 223 | " auditday = week2[calendar.MONDAY]\n", 224 | " \n", 225 | " print(\"%10s %2d\" %(calendar.month_name[month],auditday))" 226 | ] 227 | } 228 | ], 229 | "metadata": { 230 | "kernelspec": { 231 | "display_name": "Python 3", 232 | "language": "python", 233 | "name": "python3" 234 | }, 235 | "language_info": { 236 | "codemirror_mode": { 237 | "name": "ipython", 238 | "version": 3 239 | }, 240 | "file_extension": ".py", 241 | "mimetype": "text/x-python", 242 | "name": "python", 243 | "nbconvert_exporter": "python", 244 | "pygments_lexer": "ipython3", 245 | "version": "3.6.3" 246 | } 247 | }, 248 | "nbformat": 4, 249 | "nbformat_minor": 2 250 | } 251 | -------------------------------------------------------------------------------- /7-Calendar/Abhishek_CalenderModule.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analyticsbyte/Python-3-Bootcamp/a2ddcc4e5a3b2e242ad56d75853480e542771b24/7-Calendar/Abhishek_CalenderModule.pdf -------------------------------------------------------------------------------- /8-OOPs /Abhishek_OOPS_Inheritance.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": { 7 | "collapsed": true 8 | }, 9 | "outputs": [], 10 | "source": [ 11 | "class Animal():\n", 12 | " \n", 13 | " def __init__(self):\n", 14 | " print(\"Animal Created\")\n", 15 | " \n", 16 | " def who_am_i(self):\n", 17 | " print(\"i am an Animal\")\n", 18 | " \n", 19 | " def eat(self):\n", 20 | " print(\"i am eating\")" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 2, 26 | "metadata": { 27 | "collapsed": true 28 | }, 29 | "outputs": [], 30 | "source": [ 31 | "class Dog(Animal): # Inheritance\n", 32 | " \n", 33 | " def __init__(self):\n", 34 | " Animal.__init__(self) #create instance of animal class\n", 35 | " # when I create any instance of dog class\n", 36 | " print(\"Dog Created\")\n", 37 | " \n", 38 | " def who_am_i(self): # overiding methods of base class\n", 39 | " print(\"I am a Dog\")\n", 40 | " \n", 41 | " def bark(self): # create add-on methods\n", 42 | " print(\"WOOF!\")" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 3, 48 | "metadata": {}, 49 | "outputs": [ 50 | { 51 | "name": "stdout", 52 | "output_type": "stream", 53 | "text": [ 54 | "Animal Created\n", 55 | "Dog Created\n" 56 | ] 57 | } 58 | ], 59 | "source": [ 60 | "mydog = Dog() # __init__ method of dog is called and indirectly \n", 61 | " # i am calling __init__ method of Animal class" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": 4, 67 | "metadata": {}, 68 | "outputs": [ 69 | { 70 | "name": "stdout", 71 | "output_type": "stream", 72 | "text": [ 73 | "Animal Created\n" 74 | ] 75 | } 76 | ], 77 | "source": [ 78 | "myanimal = Animal()" 79 | ] 80 | }, 81 | { 82 | "cell_type": "code", 83 | "execution_count": 5, 84 | "metadata": {}, 85 | "outputs": [ 86 | { 87 | "name": "stdout", 88 | "output_type": "stream", 89 | "text": [ 90 | "i am an Animal\n" 91 | ] 92 | } 93 | ], 94 | "source": [ 95 | "myanimal.who_am_i()" 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": 6, 101 | "metadata": {}, 102 | "outputs": [ 103 | { 104 | "name": "stdout", 105 | "output_type": "stream", 106 | "text": [ 107 | "I am a Dog\n" 108 | ] 109 | } 110 | ], 111 | "source": [ 112 | "mydog.who_am_i() #after overriding" 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": 7, 118 | "metadata": {}, 119 | "outputs": [ 120 | { 121 | "name": "stdout", 122 | "output_type": "stream", 123 | "text": [ 124 | "Animal Created\n" 125 | ] 126 | } 127 | ], 128 | "source": [ 129 | "youranimal = Animal()" 130 | ] 131 | } 132 | ], 133 | "metadata": { 134 | "kernelspec": { 135 | "display_name": "Python 3", 136 | "language": "python", 137 | "name": "python3" 138 | }, 139 | "language_info": { 140 | "codemirror_mode": { 141 | "name": "ipython", 142 | "version": 3 143 | }, 144 | "file_extension": ".py", 145 | "mimetype": "text/x-python", 146 | "name": "python", 147 | "nbconvert_exporter": "python", 148 | "pygments_lexer": "ipython3", 149 | "version": "3.6.3" 150 | } 151 | }, 152 | "nbformat": 4, 153 | "nbformat_minor": 2 154 | } 155 | -------------------------------------------------------------------------------- /8-OOPs /Abhishek_OOPS_Inheritance.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analyticsbyte/Python-3-Bootcamp/a2ddcc4e5a3b2e242ad56d75853480e542771b24/8-OOPs /Abhishek_OOPS_Inheritance.pdf -------------------------------------------------------------------------------- /8-OOPs /Abhishek_OOPs_Methods.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 25, 6 | "metadata": { 7 | "collapsed": true 8 | }, 9 | "outputs": [], 10 | "source": [ 11 | "class Dog():\n", 12 | " \n", 13 | " #Class Object Attribute\n", 14 | " #Same for any instance or object of a class\n", 15 | " #So self is not required\n", 16 | " species = 'mammal'\n", 17 | " \n", 18 | " def __init__(self, breed, name):\n", 19 | " \n", 20 | " self.breed = breed\n", 21 | " self.name = name\n", 22 | " \n", 23 | " # Operations/Actions ---> Methods\n", 24 | " \n", 25 | " def bark(self,number):\n", 26 | "# print(\"WOOF! My name is {} and the number is {}\"\n", 27 | "# .format(self.name,number)) \n", 28 | "\n", 29 | " self.number = number\n", 30 | " \n", 31 | " def display(self):\n", 32 | " print(\"WOOF! My name is {} and the number is {}\"\n", 33 | " .format(self.name,self.number)) \n", 34 | " \n", 35 | " def sample(self,number):\n", 36 | " self.number=number" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 26, 42 | "metadata": { 43 | "collapsed": true 44 | }, 45 | "outputs": [], 46 | "source": [ 47 | "my_dog = Dog('Lab', 'Frankie')" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": 27, 53 | "metadata": { 54 | "collapsed": true, 55 | "scrolled": true 56 | }, 57 | "outputs": [], 58 | "source": [ 59 | "my_dog.bark(20)" 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": 28, 65 | "metadata": {}, 66 | "outputs": [ 67 | { 68 | "name": "stdout", 69 | "output_type": "stream", 70 | "text": [ 71 | "WOOF! My name is Frankie and the number is 20\n" 72 | ] 73 | } 74 | ], 75 | "source": [ 76 | "my_dog.display()" 77 | ] 78 | }, 79 | { 80 | "cell_type": "markdown", 81 | "metadata": {}, 82 | "source": [] 83 | }, 84 | { 85 | "cell_type": "markdown", 86 | "metadata": {}, 87 | "source": [ 88 | "Creating Userdefined Method ::\n" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": 29, 94 | "metadata": { 95 | "collapsed": true 96 | }, 97 | "outputs": [], 98 | "source": [ 99 | "class Circle():\n", 100 | " \n", 101 | " #class object attribute\n", 102 | " pi = 3.14\n", 103 | " \n", 104 | " def __init__(self,radius=1): #radius = 1 is a default variable\n", 105 | " \n", 106 | " self.radius = radius\n", 107 | " self.area = radius*radius*self.pi #we can write Circle.pi as its \n", 108 | " #class variable\n", 109 | " \n", 110 | " #Method\n", 111 | " def get_circumference(self):\n", 112 | " return self.radius * self.pi*2 # we can write \"Circle.pie*2\"" 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": 30, 118 | "metadata": { 119 | "collapsed": true 120 | }, 121 | "outputs": [], 122 | "source": [ 123 | "my_circle = Circle()" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": 31, 129 | "metadata": {}, 130 | "outputs": [ 131 | { 132 | "data": { 133 | "text/plain": [ 134 | "3.14" 135 | ] 136 | }, 137 | "execution_count": 31, 138 | "metadata": {}, 139 | "output_type": "execute_result" 140 | } 141 | ], 142 | "source": [ 143 | "my_circle.pi" 144 | ] 145 | }, 146 | { 147 | "cell_type": "code", 148 | "execution_count": 32, 149 | "metadata": {}, 150 | "outputs": [ 151 | { 152 | "data": { 153 | "text/plain": [ 154 | "1" 155 | ] 156 | }, 157 | "execution_count": 32, 158 | "metadata": {}, 159 | "output_type": "execute_result" 160 | } 161 | ], 162 | "source": [ 163 | "my_circle.radius #default redius value" 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": 33, 169 | "metadata": { 170 | "collapsed": true 171 | }, 172 | "outputs": [], 173 | "source": [ 174 | "my_circle = Circle(30) # overide the radius value" 175 | ] 176 | }, 177 | { 178 | "cell_type": "code", 179 | "execution_count": 34, 180 | "metadata": {}, 181 | "outputs": [ 182 | { 183 | "data": { 184 | "text/plain": [ 185 | "30" 186 | ] 187 | }, 188 | "execution_count": 34, 189 | "metadata": {}, 190 | "output_type": "execute_result" 191 | } 192 | ], 193 | "source": [ 194 | "my_circle.radius" 195 | ] 196 | }, 197 | { 198 | "cell_type": "code", 199 | "execution_count": 35, 200 | "metadata": {}, 201 | "outputs": [ 202 | { 203 | "data": { 204 | "text/plain": [ 205 | "188.4" 206 | ] 207 | }, 208 | "execution_count": 35, 209 | "metadata": {}, 210 | "output_type": "execute_result" 211 | } 212 | ], 213 | "source": [ 214 | "my_circle.get_circumference()" 215 | ] 216 | }, 217 | { 218 | "cell_type": "code", 219 | "execution_count": 36, 220 | "metadata": {}, 221 | "outputs": [ 222 | { 223 | "data": { 224 | "text/plain": [ 225 | "2826.0" 226 | ] 227 | }, 228 | "execution_count": 36, 229 | "metadata": {}, 230 | "output_type": "execute_result" 231 | } 232 | ], 233 | "source": [ 234 | "my_circle.area" 235 | ] 236 | } 237 | ], 238 | "metadata": { 239 | "kernelspec": { 240 | "display_name": "Python 3", 241 | "language": "python", 242 | "name": "python3" 243 | }, 244 | "language_info": { 245 | "codemirror_mode": { 246 | "name": "ipython", 247 | "version": 3 248 | }, 249 | "file_extension": ".py", 250 | "mimetype": "text/x-python", 251 | "name": "python", 252 | "nbconvert_exporter": "python", 253 | "pygments_lexer": "ipython3", 254 | "version": "3.6.3" 255 | } 256 | }, 257 | "nbformat": 4, 258 | "nbformat_minor": 2 259 | } 260 | -------------------------------------------------------------------------------- /8-OOPs /Abhishek_OOPs_Methods.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analyticsbyte/Python-3-Bootcamp/a2ddcc4e5a3b2e242ad56d75853480e542771b24/8-OOPs /Abhishek_OOPs_Methods.pdf -------------------------------------------------------------------------------- /8-OOPs /Abhishek_OOPs_memberVariable.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "# Defining Class with blank content ::\n", 9 | "\n" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": 27, 15 | "metadata": { 16 | "collapsed": true 17 | }, 18 | "outputs": [], 19 | "source": [ 20 | "class Sample():\n", 21 | " pass # to print blank content" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 28, 27 | "metadata": { 28 | "collapsed": true 29 | }, 30 | "outputs": [], 31 | "source": [ 32 | "my_sample = Sample()" 33 | ] 34 | }, 35 | { 36 | "cell_type": "markdown", 37 | "metadata": {}, 38 | "source": [ 39 | "# Defining Member variables ::\n" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": 29, 45 | "metadata": { 46 | "collapsed": true 47 | }, 48 | "outputs": [], 49 | "source": [ 50 | "class Dog():\n", 51 | " # __init__ is a constructor and its called automatically\n", 52 | " # when create instance or object of a class\n", 53 | " \n", 54 | " def __init__(self,mybreed): # self keyword represents the object a class\n", 55 | " \n", 56 | " # self.breed is creating an attribute \n", 57 | " # with variable name breed\n", 58 | " self.breed = mybreed\n", 59 | " " 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": 30, 65 | "metadata": { 66 | "collapsed": true 67 | }, 68 | "outputs": [], 69 | "source": [ 70 | "my_dog = Dog(mybreed = 'Huskie') # Creating objects" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": 31, 76 | "metadata": { 77 | "collapsed": true 78 | }, 79 | "outputs": [], 80 | "source": [ 81 | "your_dog = Dog(mybreed = 'german')" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 32, 87 | "metadata": {}, 88 | "outputs": [ 89 | { 90 | "data": { 91 | "text/plain": [ 92 | "'german'" 93 | ] 94 | }, 95 | "execution_count": 32, 96 | "metadata": {}, 97 | "output_type": "execute_result" 98 | } 99 | ], 100 | "source": [ 101 | "your_dog.breed" 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": 33, 107 | "metadata": {}, 108 | "outputs": [ 109 | { 110 | "data": { 111 | "text/plain": [ 112 | "'Huskie'" 113 | ] 114 | }, 115 | "execution_count": 33, 116 | "metadata": {}, 117 | "output_type": "execute_result" 118 | } 119 | ], 120 | "source": [ 121 | "my_dog.breed" 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": 34, 127 | "metadata": { 128 | "collapsed": true 129 | }, 130 | "outputs": [], 131 | "source": [ 132 | "class Cat():\n", 133 | " # __init__ is a constructor and its called automatically\n", 134 | " # when create instance or object of a class\n", 135 | " # self keyword represents the object a class\n", 136 | " \n", 137 | " def __init__(self,breed,age): # constructor with two parameters\n", 138 | " \n", 139 | " # self.breed is creating an attribute \n", 140 | " # with variable name breed\n", 141 | " self.breed = breed\n", 142 | " self.age = age" 143 | ] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "execution_count": 35, 148 | "metadata": { 149 | "collapsed": true 150 | }, 151 | "outputs": [], 152 | "source": [ 153 | "my_cat = Cat(breed='Tom', age=22)" 154 | ] 155 | }, 156 | { 157 | "cell_type": "code", 158 | "execution_count": 36, 159 | "metadata": {}, 160 | "outputs": [ 161 | { 162 | "data": { 163 | "text/plain": [ 164 | "'Tom'" 165 | ] 166 | }, 167 | "execution_count": 36, 168 | "metadata": {}, 169 | "output_type": "execute_result" 170 | } 171 | ], 172 | "source": [ 173 | "my_cat.breed" 174 | ] 175 | }, 176 | { 177 | "cell_type": "code", 178 | "execution_count": 37, 179 | "metadata": {}, 180 | "outputs": [ 181 | { 182 | "data": { 183 | "text/plain": [ 184 | "22" 185 | ] 186 | }, 187 | "execution_count": 37, 188 | "metadata": {}, 189 | "output_type": "execute_result" 190 | } 191 | ], 192 | "source": [ 193 | "my_cat.age" 194 | ] 195 | }, 196 | { 197 | "cell_type": "markdown", 198 | "metadata": {}, 199 | "source": [ 200 | "# Checking Class Variable ::\n" 201 | ] 202 | }, 203 | { 204 | "cell_type": "code", 205 | "execution_count": 38, 206 | "metadata": { 207 | "collapsed": true 208 | }, 209 | "outputs": [], 210 | "source": [ 211 | "class Dog():\n", 212 | " \n", 213 | " #Class Object Attribute\n", 214 | " #Same for any instance or object of a class\n", 215 | " #So self is not required\n", 216 | " species = 'mammal'\n", 217 | " \n", 218 | " def __init__(self, breed, name, spots):\n", 219 | " \n", 220 | " self.breed = breed\n", 221 | " self.name = name\n", 222 | " self.spots = spots" 223 | ] 224 | }, 225 | { 226 | "cell_type": "code", 227 | "execution_count": 39, 228 | "metadata": { 229 | "collapsed": true 230 | }, 231 | "outputs": [], 232 | "source": [ 233 | "my_dog = Dog(breed='lab',name='Sammy',spots= False)" 234 | ] 235 | }, 236 | { 237 | "cell_type": "code", 238 | "execution_count": 40, 239 | "metadata": {}, 240 | "outputs": [ 241 | { 242 | "data": { 243 | "text/plain": [ 244 | "'mammal'" 245 | ] 246 | }, 247 | "execution_count": 40, 248 | "metadata": {}, 249 | "output_type": "execute_result" 250 | } 251 | ], 252 | "source": [ 253 | "Dog.species # As Species is a class variable/attribute. So we can call\n", 254 | " # it with class name" 255 | ] 256 | }, 257 | { 258 | "cell_type": "code", 259 | "execution_count": 41, 260 | "metadata": {}, 261 | "outputs": [ 262 | { 263 | "data": { 264 | "text/plain": [ 265 | "'mammal'" 266 | ] 267 | }, 268 | "execution_count": 41, 269 | "metadata": {}, 270 | "output_type": "execute_result" 271 | } 272 | ], 273 | "source": [ 274 | "my_dog.species # We can call it with object name" 275 | ] 276 | }, 277 | { 278 | "cell_type": "code", 279 | "execution_count": 42, 280 | "metadata": {}, 281 | "outputs": [ 282 | { 283 | "ename": "AttributeError", 284 | "evalue": "type object 'Dog' has no attribute 'breed'", 285 | "output_type": "error", 286 | "traceback": [ 287 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 288 | "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", 289 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mDog\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbreed\u001b[0m \u001b[0;31m# breed is not class variable/attribute\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 290 | "\u001b[0;31mAttributeError\u001b[0m: type object 'Dog' has no attribute 'breed'" 291 | ] 292 | } 293 | ], 294 | "source": [ 295 | "Dog.breed # breed is not class variable/attribute" 296 | ] 297 | }, 298 | { 299 | "cell_type": "code", 300 | "execution_count": 43, 301 | "metadata": {}, 302 | "outputs": [ 303 | { 304 | "data": { 305 | "text/plain": [ 306 | "'lab'" 307 | ] 308 | }, 309 | "execution_count": 43, 310 | "metadata": {}, 311 | "output_type": "execute_result" 312 | } 313 | ], 314 | "source": [ 315 | "my_dog.breed" 316 | ] 317 | } 318 | ], 319 | "metadata": { 320 | "kernelspec": { 321 | "display_name": "Python 3", 322 | "language": "python", 323 | "name": "python3" 324 | }, 325 | "language_info": { 326 | "codemirror_mode": { 327 | "name": "ipython", 328 | "version": 3 329 | }, 330 | "file_extension": ".py", 331 | "mimetype": "text/x-python", 332 | "name": "python", 333 | "nbconvert_exporter": "python", 334 | "pygments_lexer": "ipython3", 335 | "version": "3.6.3" 336 | } 337 | }, 338 | "nbformat": 4, 339 | "nbformat_minor": 2 340 | } 341 | -------------------------------------------------------------------------------- /8-OOPs /Abhishek_OOPs_memberVariable.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analyticsbyte/Python-3-Bootcamp/a2ddcc4e5a3b2e242ad56d75853480e542771b24/8-OOPs /Abhishek_OOPs_memberVariable.pdf -------------------------------------------------------------------------------- /9-Sets/Abhishek_Sets.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 5, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "{1, 2, 3, 4}\n", 13 | "{'Hello', 1.0, (1, 2, 3)}\n" 14 | ] 15 | } 16 | ], 17 | "source": [ 18 | "# set of integers\n", 19 | "my_set = {1, 2,2,4, 3,3}\n", 20 | "print(my_set)\n", 21 | "\n", 22 | "# set of mixed datatypes\n", 23 | "my_set = {1.0, \"Hello\", (1, 2, 3)}\n", 24 | "print(my_set)" 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": 6, 30 | "metadata": {}, 31 | "outputs": [ 32 | { 33 | "data": { 34 | "text/plain": [ 35 | "{'Hello', 1.0, 9, (1, 2, 3)}" 36 | ] 37 | }, 38 | "execution_count": 6, 39 | "metadata": {}, 40 | "output_type": "execute_result" 41 | } 42 | ], 43 | "source": [ 44 | "my_set.add(9) #add any value\n", 45 | "my_set" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": 7, 51 | "metadata": {}, 52 | "outputs": [ 53 | { 54 | "data": { 55 | "text/plain": [ 56 | "{'Hello', 1.0, 2, 3, 4, 9, (1, 2, 3)}" 57 | ] 58 | }, 59 | "execution_count": 7, 60 | "metadata": {}, 61 | "output_type": "execute_result" 62 | } 63 | ], 64 | "source": [ 65 | "my_set.update([2,3,4])\n", 66 | "my_set" 67 | ] 68 | }, 69 | { 70 | "cell_type": "code", 71 | "execution_count": 8, 72 | "metadata": {}, 73 | "outputs": [ 74 | { 75 | "name": "stdout", 76 | "output_type": "stream", 77 | "text": [ 78 | "{'Hello', 1.0, 2, 3, 9, (1, 2, 3)}\n" 79 | ] 80 | } 81 | ], 82 | "source": [ 83 | "my_set.discard(4) #remove any value\n", 84 | "print(my_set)" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": 9, 90 | "metadata": {}, 91 | "outputs": [ 92 | { 93 | "name": "stdout", 94 | "output_type": "stream", 95 | "text": [ 96 | "{1, 2, 3, 4, 5, 6, 7, 8}\n" 97 | ] 98 | } 99 | ], 100 | "source": [ 101 | "A = {1, 2, 3, 4, 5}\n", 102 | "B = {4, 5, 6, 7, 8}\n", 103 | "\n", 104 | "# use | operator i.e UNION\n", 105 | "# Output: {1, 2, 3, 4, 5, 6, 7, 8}\n", 106 | "print(A | B)" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": 10, 112 | "metadata": {}, 113 | "outputs": [ 114 | { 115 | "name": "stdout", 116 | "output_type": "stream", 117 | "text": [ 118 | "{4, 5}\n" 119 | ] 120 | } 121 | ], 122 | "source": [ 123 | "# initialize A and B\n", 124 | "A = {1, 2, 3, 4, 5}\n", 125 | "B = {4, 5, 6, 7, 8}\n", 126 | "\n", 127 | "# use & operator i.e INTERSECTION\n", 128 | "# Output: {4, 5}\n", 129 | "print(A & B)" 130 | ] 131 | } 132 | ], 133 | "metadata": { 134 | "kernelspec": { 135 | "display_name": "Python 3", 136 | "language": "python", 137 | "name": "python3" 138 | }, 139 | "language_info": { 140 | "codemirror_mode": { 141 | "name": "ipython", 142 | "version": 3 143 | }, 144 | "file_extension": ".py", 145 | "mimetype": "text/x-python", 146 | "name": "python", 147 | "nbconvert_exporter": "python", 148 | "pygments_lexer": "ipython3", 149 | "version": "3.6.3" 150 | } 151 | }, 152 | "nbformat": 4, 153 | "nbformat_minor": 2 154 | } 155 | -------------------------------------------------------------------------------- /9-Sets/Abhishek_Sets.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/analyticsbyte/Python-3-Bootcamp/a2ddcc4e5a3b2e242ad56d75853480e542771b24/9-Sets/Abhishek_Sets.pdf -------------------------------------------------------------------------------- /Numpy/Abhishek - Numpy .ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "import numpy as np" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "## Creating array and multi dimentional array from a list" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 3, 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "list1 = [1,2,3,4]" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 4, 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "array1 = np.array(list1)" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": 5, 40 | "metadata": {}, 41 | "outputs": [ 42 | { 43 | "data": { 44 | "text/plain": [ 45 | "array([1, 2, 3, 4])" 46 | ] 47 | }, 48 | "execution_count": 5, 49 | "metadata": {}, 50 | "output_type": "execute_result" 51 | } 52 | ], 53 | "source": [ 54 | "array1" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": 6, 60 | "metadata": {}, 61 | "outputs": [], 62 | "source": [ 63 | "list2 = [11,22,33,44]" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 7, 69 | "metadata": {}, 70 | "outputs": [], 71 | "source": [ 72 | "mylist = [list1,list2]" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": 8, 78 | "metadata": {}, 79 | "outputs": [ 80 | { 81 | "data": { 82 | "text/plain": [ 83 | "[[1, 2, 3, 4], [11, 22, 33, 44]]" 84 | ] 85 | }, 86 | "execution_count": 8, 87 | "metadata": {}, 88 | "output_type": "execute_result" 89 | } 90 | ], 91 | "source": [ 92 | "mylist" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 9, 98 | "metadata": {}, 99 | "outputs": [], 100 | "source": [ 101 | "array2 = np.array(mylist)" 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": 10, 107 | "metadata": {}, 108 | "outputs": [ 109 | { 110 | "data": { 111 | "text/plain": [ 112 | "array([[ 1, 2, 3, 4],\n", 113 | " [11, 22, 33, 44]])" 114 | ] 115 | }, 116 | "execution_count": 10, 117 | "metadata": {}, 118 | "output_type": "execute_result" 119 | } 120 | ], 121 | "source": [ 122 | "array2" 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": 12, 128 | "metadata": {}, 129 | "outputs": [ 130 | { 131 | "data": { 132 | "text/plain": [ 133 | "(2, 4)" 134 | ] 135 | }, 136 | "execution_count": 12, 137 | "metadata": {}, 138 | "output_type": "execute_result" 139 | } 140 | ], 141 | "source": [ 142 | "array2.shape" 143 | ] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "execution_count": 14, 148 | "metadata": {}, 149 | "outputs": [ 150 | { 151 | "data": { 152 | "text/plain": [ 153 | "dtype('int64')" 154 | ] 155 | }, 156 | "execution_count": 14, 157 | "metadata": {}, 158 | "output_type": "execute_result" 159 | } 160 | ], 161 | "source": [ 162 | "array2.dtype" 163 | ] 164 | }, 165 | { 166 | "cell_type": "markdown", 167 | "metadata": {}, 168 | "source": [ 169 | "## Different functions of an array " 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": 17, 175 | "metadata": {}, 176 | "outputs": [ 177 | { 178 | "data": { 179 | "text/plain": [ 180 | "array([0., 0., 0., 0., 0.])" 181 | ] 182 | }, 183 | "execution_count": 17, 184 | "metadata": {}, 185 | "output_type": "execute_result" 186 | } 187 | ], 188 | "source": [ 189 | "np.zeros(5) #as point is there so they are decimals" 190 | ] 191 | }, 192 | { 193 | "cell_type": "code", 194 | "execution_count": 16, 195 | "metadata": {}, 196 | "outputs": [], 197 | "source": [ 198 | "zeroes_array = np.zeros(5)" 199 | ] 200 | }, 201 | { 202 | "cell_type": "code", 203 | "execution_count": 18, 204 | "metadata": {}, 205 | "outputs": [ 206 | { 207 | "data": { 208 | "text/plain": [ 209 | "array([0., 0., 0., 0., 0.])" 210 | ] 211 | }, 212 | "execution_count": 18, 213 | "metadata": {}, 214 | "output_type": "execute_result" 215 | } 216 | ], 217 | "source": [ 218 | "zeroes_array" 219 | ] 220 | }, 221 | { 222 | "cell_type": "code", 223 | "execution_count": 19, 224 | "metadata": {}, 225 | "outputs": [ 226 | { 227 | "data": { 228 | "text/plain": [ 229 | "dtype('float64')" 230 | ] 231 | }, 232 | "execution_count": 19, 233 | "metadata": {}, 234 | "output_type": "execute_result" 235 | } 236 | ], 237 | "source": [ 238 | "zeroes_array.dtype" 239 | ] 240 | }, 241 | { 242 | "cell_type": "code", 243 | "execution_count": 20, 244 | "metadata": {}, 245 | "outputs": [ 246 | { 247 | "data": { 248 | "text/plain": [ 249 | "array([1., 1., 1., 1.])" 250 | ] 251 | }, 252 | "execution_count": 20, 253 | "metadata": {}, 254 | "output_type": "execute_result" 255 | } 256 | ], 257 | "source": [ 258 | "np.ones(4)" 259 | ] 260 | }, 261 | { 262 | "cell_type": "code", 263 | "execution_count": 22, 264 | "metadata": {}, 265 | "outputs": [ 266 | { 267 | "data": { 268 | "text/plain": [ 269 | "array([[1., 1., 1., 1.],\n", 270 | " [1., 1., 1., 1.],\n", 271 | " [1., 1., 1., 1.],\n", 272 | " [1., 1., 1., 1.]])" 273 | ] 274 | }, 275 | "execution_count": 22, 276 | "metadata": {}, 277 | "output_type": "execute_result" 278 | } 279 | ], 280 | "source": [ 281 | "np.ones([4,4]) #multi dimensional array" 282 | ] 283 | }, 284 | { 285 | "cell_type": "code", 286 | "execution_count": 23, 287 | "metadata": {}, 288 | "outputs": [ 289 | { 290 | "data": { 291 | "text/plain": [ 292 | "array([[1., 0., 0., 0., 0.],\n", 293 | " [0., 1., 0., 0., 0.],\n", 294 | " [0., 0., 1., 0., 0.],\n", 295 | " [0., 0., 0., 1., 0.],\n", 296 | " [0., 0., 0., 0., 1.]])" 297 | ] 298 | }, 299 | "execution_count": 23, 300 | "metadata": {}, 301 | "output_type": "execute_result" 302 | } 303 | ], 304 | "source": [ 305 | "np.eye(5) #creating on identity matrix with diagonal one 5x5" 306 | ] 307 | }, 308 | { 309 | "cell_type": "code", 310 | "execution_count": 38, 311 | "metadata": {}, 312 | "outputs": [], 313 | "source": [ 314 | "array3 = np.arange(5,50,2) # (start, last, step)" 315 | ] 316 | }, 317 | { 318 | "cell_type": "code", 319 | "execution_count": 39, 320 | "metadata": {}, 321 | "outputs": [ 322 | { 323 | "data": { 324 | "text/plain": [ 325 | "array([ 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37,\n", 326 | " 39, 41, 43, 45, 47, 49])" 327 | ] 328 | }, 329 | "execution_count": 39, 330 | "metadata": {}, 331 | "output_type": "execute_result" 332 | } 333 | ], 334 | "source": [ 335 | "array3" 336 | ] 337 | }, 338 | { 339 | "cell_type": "code", 340 | "execution_count": null, 341 | "metadata": {}, 342 | "outputs": [], 343 | "source": [] 344 | }, 345 | { 346 | "cell_type": "markdown", 347 | "metadata": {}, 348 | "source": [ 349 | "## Arithmatic operations using array" 350 | ] 351 | }, 352 | { 353 | "cell_type": "code", 354 | "execution_count": 26, 355 | "metadata": {}, 356 | "outputs": [ 357 | { 358 | "data": { 359 | "text/plain": [ 360 | "array([1, 2, 3, 4])" 361 | ] 362 | }, 363 | "execution_count": 26, 364 | "metadata": {}, 365 | "output_type": "execute_result" 366 | } 367 | ], 368 | "source": [ 369 | "array1" 370 | ] 371 | }, 372 | { 373 | "cell_type": "code", 374 | "execution_count": 27, 375 | "metadata": {}, 376 | "outputs": [ 377 | { 378 | "data": { 379 | "text/plain": [ 380 | "array([[ 1, 2, 3, 4],\n", 381 | " [11, 22, 33, 44]])" 382 | ] 383 | }, 384 | "execution_count": 27, 385 | "metadata": {}, 386 | "output_type": "execute_result" 387 | } 388 | ], 389 | "source": [ 390 | "array2" 391 | ] 392 | }, 393 | { 394 | "cell_type": "code", 395 | "execution_count": 30, 396 | "metadata": {}, 397 | "outputs": [ 398 | { 399 | "data": { 400 | "text/plain": [ 401 | "array([[ 1, 4, 9, 16],\n", 402 | " [ 11, 44, 99, 176]])" 403 | ] 404 | }, 405 | "execution_count": 30, 406 | "metadata": {}, 407 | "output_type": "execute_result" 408 | } 409 | ], 410 | "source": [ 411 | "array1 * array2 # multiplying 1D array with 2D array" 412 | ] 413 | }, 414 | { 415 | "cell_type": "code", 416 | "execution_count": 31, 417 | "metadata": {}, 418 | "outputs": [ 419 | { 420 | "data": { 421 | "text/plain": [ 422 | "array([[ 0, 0, 0, 0],\n", 423 | " [-10, -20, -30, -40]])" 424 | ] 425 | }, 426 | "execution_count": 31, 427 | "metadata": {}, 428 | "output_type": "execute_result" 429 | } 430 | ], 431 | "source": [ 432 | "array1 - array2" 433 | ] 434 | }, 435 | { 436 | "cell_type": "code", 437 | "execution_count": 32, 438 | "metadata": {}, 439 | "outputs": [ 440 | { 441 | "data": { 442 | "text/plain": [ 443 | "array([1. , 0.5 , 0.33333333, 0.25 ])" 444 | ] 445 | }, 446 | "execution_count": 32, 447 | "metadata": {}, 448 | "output_type": "execute_result" 449 | } 450 | ], 451 | "source": [ 452 | "1/array1" 453 | ] 454 | }, 455 | { 456 | "cell_type": "code", 457 | "execution_count": 34, 458 | "metadata": {}, 459 | "outputs": [ 460 | { 461 | "data": { 462 | "text/plain": [ 463 | "array([ 1, 4, 9, 16])" 464 | ] 465 | }, 466 | "execution_count": 34, 467 | "metadata": {}, 468 | "output_type": "execute_result" 469 | } 470 | ], 471 | "source": [ 472 | "array1**2 # exponential operation" 473 | ] 474 | }, 475 | { 476 | "cell_type": "code", 477 | "execution_count": null, 478 | "metadata": {}, 479 | "outputs": [], 480 | "source": [] 481 | }, 482 | { 483 | "cell_type": "markdown", 484 | "metadata": {}, 485 | "source": [ 486 | "## Array Indexing" 487 | ] 488 | }, 489 | { 490 | "cell_type": "code", 491 | "execution_count": 40, 492 | "metadata": {}, 493 | "outputs": [ 494 | { 495 | "data": { 496 | "text/plain": [ 497 | "array([ 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37,\n", 498 | " 39, 41, 43, 45, 47, 49])" 499 | ] 500 | }, 501 | "execution_count": 40, 502 | "metadata": {}, 503 | "output_type": "execute_result" 504 | } 505 | ], 506 | "source": [ 507 | "array3" 508 | ] 509 | }, 510 | { 511 | "cell_type": "code", 512 | "execution_count": 42, 513 | "metadata": {}, 514 | "outputs": [ 515 | { 516 | "data": { 517 | "text/plain": [ 518 | "19" 519 | ] 520 | }, 521 | "execution_count": 42, 522 | "metadata": {}, 523 | "output_type": "execute_result" 524 | } 525 | ], 526 | "source": [ 527 | "array3[7]" 528 | ] 529 | }, 530 | { 531 | "cell_type": "code", 532 | "execution_count": 43, 533 | "metadata": {}, 534 | "outputs": [ 535 | { 536 | "data": { 537 | "text/plain": [ 538 | "array([ 7, 9, 11, 13, 15, 17])" 539 | ] 540 | }, 541 | "execution_count": 43, 542 | "metadata": {}, 543 | "output_type": "execute_result" 544 | } 545 | ], 546 | "source": [ 547 | "array3[1:7]" 548 | ] 549 | }, 550 | { 551 | "cell_type": "code", 552 | "execution_count": 44, 553 | "metadata": {}, 554 | "outputs": [ 555 | { 556 | "data": { 557 | "text/plain": [ 558 | "array([ 5, 7, 9, 11, 13])" 559 | ] 560 | }, 561 | "execution_count": 44, 562 | "metadata": {}, 563 | "output_type": "execute_result" 564 | } 565 | ], 566 | "source": [ 567 | "array3[0:5]" 568 | ] 569 | }, 570 | { 571 | "cell_type": "code", 572 | "execution_count": 49, 573 | "metadata": {}, 574 | "outputs": [ 575 | { 576 | "data": { 577 | "text/plain": [ 578 | "array([2000, 2000, 2000, 2000, 2000, 15, 17, 19, 21, 23, 25,\n", 579 | " 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47,\n", 580 | " 49])" 581 | ] 582 | }, 583 | "execution_count": 49, 584 | "metadata": {}, 585 | "output_type": "execute_result" 586 | } 587 | ], 588 | "source": [ 589 | "array3[:]" 590 | ] 591 | }, 592 | { 593 | "cell_type": "code", 594 | "execution_count": 47, 595 | "metadata": {}, 596 | "outputs": [], 597 | "source": [ 598 | "array3[0:5] = 2000 #assigned 2000 for first 5 items" 599 | ] 600 | }, 601 | { 602 | "cell_type": "code", 603 | "execution_count": 48, 604 | "metadata": {}, 605 | "outputs": [ 606 | { 607 | "data": { 608 | "text/plain": [ 609 | "array([2000, 2000, 2000, 2000, 2000, 15, 17, 19, 21, 23, 25,\n", 610 | " 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47,\n", 611 | " 49])" 612 | ] 613 | }, 614 | "execution_count": 48, 615 | "metadata": {}, 616 | "output_type": "execute_result" 617 | } 618 | ], 619 | "source": [ 620 | "array3" 621 | ] 622 | }, 623 | { 624 | "cell_type": "code", 625 | "execution_count": 54, 626 | "metadata": {}, 627 | "outputs": [], 628 | "source": [ 629 | "array_copy = array3.copy() #copying any array" 630 | ] 631 | }, 632 | { 633 | "cell_type": "code", 634 | "execution_count": 55, 635 | "metadata": {}, 636 | "outputs": [ 637 | { 638 | "data": { 639 | "text/plain": [ 640 | "array([2000, 2000, 2000, 2000, 2000, 15, 17, 19, 21, 23, 25,\n", 641 | " 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47,\n", 642 | " 49])" 643 | ] 644 | }, 645 | "execution_count": 55, 646 | "metadata": {}, 647 | "output_type": "execute_result" 648 | } 649 | ], 650 | "source": [ 651 | "array_copy" 652 | ] 653 | }, 654 | { 655 | "cell_type": "markdown", 656 | "metadata": {}, 657 | "source": [ 658 | "##### 2D array indexing" 659 | ] 660 | }, 661 | { 662 | "cell_type": "code", 663 | "execution_count": 56, 664 | "metadata": {}, 665 | "outputs": [ 666 | { 667 | "data": { 668 | "text/plain": [ 669 | "array([[ 1, 2, 3, 4],\n", 670 | " [11, 22, 33, 44]])" 671 | ] 672 | }, 673 | "execution_count": 56, 674 | "metadata": {}, 675 | "output_type": "execute_result" 676 | } 677 | ], 678 | "source": [ 679 | "array2" 680 | ] 681 | }, 682 | { 683 | "cell_type": "code", 684 | "execution_count": 60, 685 | "metadata": {}, 686 | "outputs": [ 687 | { 688 | "data": { 689 | "text/plain": [ 690 | "array([1, 2, 3, 4])" 691 | ] 692 | }, 693 | "execution_count": 60, 694 | "metadata": {}, 695 | "output_type": "execute_result" 696 | } 697 | ], 698 | "source": [ 699 | "array2[0]" 700 | ] 701 | }, 702 | { 703 | "cell_type": "code", 704 | "execution_count": 61, 705 | "metadata": {}, 706 | "outputs": [ 707 | { 708 | "data": { 709 | "text/plain": [ 710 | "33" 711 | ] 712 | }, 713 | "execution_count": 61, 714 | "metadata": {}, 715 | "output_type": "execute_result" 716 | } 717 | ], 718 | "source": [ 719 | "array2[1][2]" 720 | ] 721 | }, 722 | { 723 | "cell_type": "code", 724 | "execution_count": 63, 725 | "metadata": {}, 726 | "outputs": [ 727 | { 728 | "data": { 729 | "text/plain": [ 730 | "array([[ 2, 3],\n", 731 | " [22, 33]])" 732 | ] 733 | }, 734 | "execution_count": 63, 735 | "metadata": {}, 736 | "output_type": "execute_result" 737 | } 738 | ], 739 | "source": [ 740 | "array2[:,1:3]" 741 | ] 742 | }, 743 | { 744 | "cell_type": "markdown", 745 | "metadata": {}, 746 | "source": [ 747 | "## Matrix Processing" 748 | ] 749 | }, 750 | { 751 | "cell_type": "code", 752 | "execution_count": 64, 753 | "metadata": {}, 754 | "outputs": [], 755 | "source": [ 756 | "arr_mat = np.arange(50)" 757 | ] 758 | }, 759 | { 760 | "cell_type": "code", 761 | "execution_count": 65, 762 | "metadata": {}, 763 | "outputs": [ 764 | { 765 | "data": { 766 | "text/plain": [ 767 | "array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,\n", 768 | " 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,\n", 769 | " 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49])" 770 | ] 771 | }, 772 | "execution_count": 65, 773 | "metadata": {}, 774 | "output_type": "execute_result" 775 | } 776 | ], 777 | "source": [ 778 | "arr_mat" 779 | ] 780 | }, 781 | { 782 | "cell_type": "code", 783 | "execution_count": 66, 784 | "metadata": {}, 785 | "outputs": [], 786 | "source": [ 787 | "arr_mat = np.arange(50).reshape(10,5)" 788 | ] 789 | }, 790 | { 791 | "cell_type": "code", 792 | "execution_count": 67, 793 | "metadata": {}, 794 | "outputs": [ 795 | { 796 | "data": { 797 | "text/plain": [ 798 | "array([[ 0, 1, 2, 3, 4],\n", 799 | " [ 5, 6, 7, 8, 9],\n", 800 | " [10, 11, 12, 13, 14],\n", 801 | " [15, 16, 17, 18, 19],\n", 802 | " [20, 21, 22, 23, 24],\n", 803 | " [25, 26, 27, 28, 29],\n", 804 | " [30, 31, 32, 33, 34],\n", 805 | " [35, 36, 37, 38, 39],\n", 806 | " [40, 41, 42, 43, 44],\n", 807 | " [45, 46, 47, 48, 49]])" 808 | ] 809 | }, 810 | "execution_count": 67, 811 | "metadata": {}, 812 | "output_type": "execute_result" 813 | } 814 | ], 815 | "source": [ 816 | "arr_mat" 817 | ] 818 | }, 819 | { 820 | "cell_type": "code", 821 | "execution_count": 69, 822 | "metadata": {}, 823 | "outputs": [ 824 | { 825 | "data": { 826 | "text/plain": [ 827 | "array([[ 0, 5, 10, 15, 20, 25, 30, 35, 40, 45],\n", 828 | " [ 1, 6, 11, 16, 21, 26, 31, 36, 41, 46],\n", 829 | " [ 2, 7, 12, 17, 22, 27, 32, 37, 42, 47],\n", 830 | " [ 3, 8, 13, 18, 23, 28, 33, 38, 43, 48],\n", 831 | " [ 4, 9, 14, 19, 24, 29, 34, 39, 44, 49]])" 832 | ] 833 | }, 834 | "execution_count": 69, 835 | "metadata": {}, 836 | "output_type": "execute_result" 837 | } 838 | ], 839 | "source": [ 840 | "arr_mat.T #transpose of a matrix" 841 | ] 842 | }, 843 | { 844 | "cell_type": "code", 845 | "execution_count": 71, 846 | "metadata": {}, 847 | "outputs": [ 848 | { 849 | "data": { 850 | "text/plain": [ 851 | "array([[7125, 7350, 7575, 7800, 8025],\n", 852 | " [7350, 7585, 7820, 8055, 8290],\n", 853 | " [7575, 7820, 8065, 8310, 8555],\n", 854 | " [7800, 8055, 8310, 8565, 8820],\n", 855 | " [8025, 8290, 8555, 8820, 9085]])" 856 | ] 857 | }, 858 | "execution_count": 71, 859 | "metadata": {}, 860 | "output_type": "execute_result" 861 | } 862 | ], 863 | "source": [ 864 | "np.dot(arr_mat.T,arr_mat) #dot product" 865 | ] 866 | }, 867 | { 868 | "cell_type": "markdown", 869 | "metadata": {}, 870 | "source": [ 871 | "## Universal Functions" 872 | ] 873 | }, 874 | { 875 | "cell_type": "code", 876 | "execution_count": 72, 877 | "metadata": {}, 878 | "outputs": [ 879 | { 880 | "data": { 881 | "text/plain": [ 882 | "True" 883 | ] 884 | }, 885 | "execution_count": 72, 886 | "metadata": {}, 887 | "output_type": "execute_result" 888 | } 889 | ], 890 | "source": [ 891 | "web = 'https://docs.scipy.org/doc/numpy/reference/ufuncs.html#available-ufuncs'\n", 892 | "import webbrowser\n", 893 | "webbrowser.open(web)" 894 | ] 895 | }, 896 | { 897 | "cell_type": "code", 898 | "execution_count": null, 899 | "metadata": {}, 900 | "outputs": [], 901 | "source": [ 902 | "broad casting" 903 | ] 904 | } 905 | ], 906 | "metadata": { 907 | "kernelspec": { 908 | "display_name": "Python 3", 909 | "language": "python", 910 | "name": "python3" 911 | }, 912 | "language_info": { 913 | "codemirror_mode": { 914 | "name": "ipython", 915 | "version": 3 916 | }, 917 | "file_extension": ".py", 918 | "mimetype": "text/x-python", 919 | "name": "python", 920 | "nbconvert_exporter": "python", 921 | "pygments_lexer": "ipython3", 922 | "version": "3.7.6" 923 | } 924 | }, 925 | "nbformat": 4, 926 | "nbformat_minor": 4 927 | } 928 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python-3-Bootcamp 2 | ## Welcome to the Repository for the Complete Python Bootcamp 3 | Course Files for Complete Python 3 Bootcamp Course 4 | This is the Repository for the "Complete Python Bootcamp". 5 | In this repo you will find all the accompanying Jupyter Notebooks for the course. 6 | You can download the .ipynb files onto your own computer for convenience. 7 | Enjoy the content! 8 | --------------------------------------------------------------------------------