├── .gitignore ├── LICENSE ├── README.md ├── notebooks ├── .ipynb_checkpoints │ └── py3-in-one-pic-checkpoint.ipynb ├── README.md └── py3-in-one-pic.ipynb ├── py3 in one pic.mindnode ├── QuickLook │ └── Preview.jpg ├── contents.xml ├── style.mindnodestyle │ ├── contents.xml │ └── metadata.plist └── viewState.plist ├── py3 in one pic.png └── src ├── basicSyntax.py ├── nativeDatatypes.py └── this.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | venv3/ 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Yusheng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python3 in one pic 2 | 3 | [ Languages: [English](README.md) ] 4 | 5 | 6 | [![Gitter chat button](https://img.shields.io/badge/gitter-Join%20Chat-brightgreen.svg)](https://gitter.im/coodict/python3-in-one-pic) 7 | [![BitCoin donate button](https://img.shields.io/badge/bitcoin-donate-yellow.svg)](https://www.coinbase.com/rainyear) 8 | 9 | 10 | ## Notebook 11 | 12 | [IPython Notebook Version](https://github.com/coodict/python3-in-one-pic/blob/master/notebooks/py3-in-one-pic.ipynb) 13 | 14 | ## Preview 15 | 16 | ![py3 in one pic](py3%20in%20one%20pic.png) 17 | 18 | ## Releated projects 19 | 20 | * [Javascript in one pic](https://github.com/coodict/javascript-in-one-pic) 21 | * Go in one pic (in preparation) 22 | 23 | ## TODO 24 | - [ ] Use IPython notebook, it's really very cool! 25 | 26 | - [X] `import this` 27 | - [X] Basic Syntax 28 | - [ ] Native Datatypes 29 | - [X] Number 30 | - [X] String 31 | - [X] Boolean 32 | - [X] None 33 | - [X] Byte 34 | - [X] List 35 | - [X] Tuple 36 | - [X] Set 37 | - [X] Dict 38 | - [ ] Operators & Casting 39 | - [ ] Flow Control 40 | - [ ] `if/elif/else` 41 | - [ ] `for...in...` 42 | - [ ] `while` 43 | - [ ] Function 44 | - [ ] Class(OOP) 45 | - [ ] Module 46 | - [ ] Pythonic 47 | - [ ] Standard Libraries 48 | - [ ] `os, sys` 49 | - [ ] `datetime` 50 | 51 | ## Donation 52 | 53 | If you find this project helpful, please consider making a donation with [bitcoin](https://www.coinbase.com/rainyear) or [other way](https://github.com/rainyear/lolita/wiki/Donation) :beers: 54 | 55 | ## References 56 | 57 | 1. [Python 3.4.3 documentation](https://docs.python.org/3/index.html) 58 | 2. [Dive Into Python 3](http://www.diveintopython3.net/table-of-contents.html) 59 | 3. Writing Idiomatic Python 3.3 60 | 4. [Google Python Style Guide](https://google-styleguide.googlecode.com/svn/trunk/pyguide.html) 61 | 5. [廖雪峰的Python教程](http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000) 62 | 63 | ## License 64 | See the [LICENSE](LICENSE) file for license rights and limitations (MIT). 65 | -------------------------------------------------------------------------------- /notebooks/.ipynb_checkpoints/py3-in-one-pic-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": { 7 | "collapsed": false 8 | }, 9 | "outputs": [ 10 | { 11 | "name": "stdout", 12 | "output_type": "stream", 13 | "text": [ 14 | "The Zen of Python, by Tim Peters\n", 15 | "\n", 16 | "Beautiful is better than ugly.\n", 17 | "Explicit is better than implicit.\n", 18 | "Simple is better than complex.\n", 19 | "Complex is better than complicated.\n", 20 | "Flat is better than nested.\n", 21 | "Sparse is better than dense.\n", 22 | "Readability counts.\n", 23 | "Special cases aren't special enough to break the rules.\n", 24 | "Although practicality beats purity.\n", 25 | "Errors should never pass silently.\n", 26 | "Unless explicitly silenced.\n", 27 | "In the face of ambiguity, refuse the temptation to guess.\n", 28 | "There should be one-- and preferably only one --obvious way to do it.\n", 29 | "Although that way may not be obvious at first unless you're Dutch.\n", 30 | "Now is better than never.\n", 31 | "Although never is often better than *right* now.\n", 32 | "If the implementation is hard to explain, it's a bad idea.\n", 33 | "If the implementation is easy to explain, it may be a good idea.\n", 34 | "Namespaces are one honking great idea -- let's do more of those!\n" 35 | ] 36 | } 37 | ], 38 | "source": [ 39 | "import this" 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": {}, 45 | "source": [ 46 | "### Native DataTypes\n", 47 | "#### Number" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": 2, 53 | "metadata": { 54 | "collapsed": false 55 | }, 56 | "outputs": [ 57 | { 58 | "name": "stdout", 59 | "output_type": "stream", 60 | "text": [ 61 | "\n" 62 | ] 63 | } 64 | ], 65 | "source": [ 66 | "## integer\n", 67 | "a = 1\n", 68 | "b = 0x10 # 16\n", 69 | "print(type(a)) # " 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 3, 75 | "metadata": { 76 | "collapsed": false 77 | }, 78 | "outputs": [ 79 | { 80 | "name": "stdout", 81 | "output_type": "stream", 82 | "text": [ 83 | "\n" 84 | ] 85 | } 86 | ], 87 | "source": [ 88 | "## float\n", 89 | "c = 1.2\n", 90 | "d = .5 # 0.5\n", 91 | "g = .314e1 # 3.14\n", 92 | "print(type(g)) # " 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 4, 98 | "metadata": { 99 | "collapsed": false 100 | }, 101 | "outputs": [ 102 | { 103 | "name": "stdout", 104 | "output_type": "stream", 105 | "text": [ 106 | "\n", 107 | "True\n" 108 | ] 109 | } 110 | ], 111 | "source": [ 112 | "## complex\n", 113 | "e = 1+2j\n", 114 | "f = complex(1, 2)\n", 115 | "print(type(e)) # \n", 116 | "print(f == e) # True" 117 | ] 118 | }, 119 | { 120 | "cell_type": "markdown", 121 | "metadata": {}, 122 | "source": [ 123 | "#### String" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": 5, 129 | "metadata": { 130 | "collapsed": false 131 | }, 132 | "outputs": [ 133 | { 134 | "name": "stdout", 135 | "output_type": "stream", 136 | "text": [ 137 | "\n", 138 | "🐶\n", 139 | ", Dogge's home, \n", 140 | "Hello,\n", 141 | "Dogge!\n", 142 | "\n" 143 | ] 144 | } 145 | ], 146 | "source": [ 147 | "s1 = '🐶\\n'\n", 148 | "s2 = \"Dogge's home\"\n", 149 | "s3 = \"\"\"\n", 150 | "Hello,\n", 151 | "Dogge!\n", 152 | "\"\"\"\n", 153 | "print(type(s1)) # \n", 154 | "print(\"%s, %s, %s\" % (s1, s2, s3))" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": 6, 160 | "metadata": { 161 | "collapsed": false 162 | }, 163 | "outputs": [ 164 | { 165 | "name": "stdout", 166 | "output_type": "stream", 167 | "text": [ 168 | "2\n" 169 | ] 170 | } 171 | ], 172 | "source": [ 173 | "## Length\n", 174 | "print(len(s1)) # 2" 175 | ] 176 | }, 177 | { 178 | "cell_type": "code", 179 | "execution_count": 7, 180 | "metadata": { 181 | "collapsed": false 182 | }, 183 | "outputs": [ 184 | { 185 | "name": "stdout", 186 | "output_type": "stream", 187 | "text": [ 188 | "学:习\n" 189 | ] 190 | } 191 | ], 192 | "source": [ 193 | "## Slicing\n", 194 | "s = '学而时习之'\n", 195 | "print('{0}:{1}'.format(s[0], s[-2])) # 学:习" 196 | ] 197 | }, 198 | { 199 | "cell_type": "markdown", 200 | "metadata": {}, 201 | "source": [ 202 | "#### Byte" 203 | ] 204 | }, 205 | { 206 | "cell_type": "code", 207 | "execution_count": 8, 208 | "metadata": { 209 | "collapsed": false 210 | }, 211 | "outputs": [ 212 | { 213 | "name": "stdout", 214 | "output_type": "stream", 215 | "text": [ 216 | "\n", 217 | "False\n", 218 | "True\n" 219 | ] 220 | } 221 | ], 222 | "source": [ 223 | "# Byte\n", 224 | "## 0-255/x00-xff\n", 225 | "byt = b'abc'\n", 226 | "print(type(byt)) # \n", 227 | "print(byt[0] == 'a')# False\n", 228 | "print(byt[0] == 97) # True" 229 | ] 230 | }, 231 | { 232 | "cell_type": "code", 233 | "execution_count": 9, 234 | "metadata": { 235 | "collapsed": false 236 | }, 237 | "outputs": [ 238 | { 239 | "name": "stdout", 240 | "output_type": "stream", 241 | "text": [ 242 | "3\n" 243 | ] 244 | } 245 | ], 246 | "source": [ 247 | "## Length\n", 248 | "print(len(byt)) # 3" 249 | ] 250 | }, 251 | { 252 | "cell_type": "markdown", 253 | "metadata": {}, 254 | "source": [ 255 | "#### Boolean" 256 | ] 257 | }, 258 | { 259 | "cell_type": "code", 260 | "execution_count": 10, 261 | "metadata": { 262 | "collapsed": false 263 | }, 264 | "outputs": [ 265 | { 266 | "name": "stdout", 267 | "output_type": "stream", 268 | "text": [ 269 | "\n" 270 | ] 271 | } 272 | ], 273 | "source": [ 274 | "True\n", 275 | "False\n", 276 | "print(type(True)) # " 277 | ] 278 | }, 279 | { 280 | "cell_type": "markdown", 281 | "metadata": {}, 282 | "source": [ 283 | "#### None" 284 | ] 285 | }, 286 | { 287 | "cell_type": "code", 288 | "execution_count": 11, 289 | "metadata": { 290 | "collapsed": false 291 | }, 292 | "outputs": [ 293 | { 294 | "name": "stdout", 295 | "output_type": "stream", 296 | "text": [ 297 | "True\n", 298 | "\n" 299 | ] 300 | } 301 | ], 302 | "source": [ 303 | "print(None is None) # True\n", 304 | "print(type(None)) # " 305 | ] 306 | }, 307 | { 308 | "cell_type": "markdown", 309 | "metadata": {}, 310 | "source": [ 311 | "#### List" 312 | ] 313 | }, 314 | { 315 | "cell_type": "code", 316 | "execution_count": 12, 317 | "metadata": { 318 | "collapsed": false 319 | }, 320 | "outputs": [ 321 | { 322 | "name": "stdout", 323 | "output_type": "stream", 324 | "text": [ 325 | "\n" 326 | ] 327 | } 328 | ], 329 | "source": [ 330 | "l = ['python', 3, 'in', 'one']\n", 331 | "print(type(l)) # " 332 | ] 333 | }, 334 | { 335 | "cell_type": "code", 336 | "execution_count": 13, 337 | "metadata": { 338 | "collapsed": false 339 | }, 340 | "outputs": [ 341 | { 342 | "name": "stdout", 343 | "output_type": "stream", 344 | "text": [ 345 | "4\n" 346 | ] 347 | } 348 | ], 349 | "source": [ 350 | "## Length\n", 351 | "print(len(l)) # 4" 352 | ] 353 | }, 354 | { 355 | "cell_type": "code", 356 | "execution_count": 14, 357 | "metadata": { 358 | "collapsed": false 359 | }, 360 | "outputs": [ 361 | { 362 | "name": "stdout", 363 | "output_type": "stream", 364 | "text": [ 365 | "python\n", 366 | "one\n", 367 | "[3, 'in']\n" 368 | ] 369 | } 370 | ], 371 | "source": [ 372 | "## Slicing\n", 373 | "print(l[0]) # 'python'\n", 374 | "print(l[-1]) # 'one'\n", 375 | "print(l[1:-1]) # [3, 'in']" 376 | ] 377 | }, 378 | { 379 | "cell_type": "code", 380 | "execution_count": 15, 381 | "metadata": { 382 | "collapsed": false 383 | }, 384 | "outputs": [ 385 | { 386 | "name": "stdout", 387 | "output_type": "stream", 388 | "text": [ 389 | "['python', 3, 'in', 'one', 'pic']\n", 390 | "['python', 3, '.4.1', 'in', 'one', 'pic']\n", 391 | "['python', 3, '.4.1', 'in', 'one', 'pic', '!', '!']\n" 392 | ] 393 | } 394 | ], 395 | "source": [ 396 | "## Alter\n", 397 | "l.append('pic') # None\n", 398 | "print(l)\n", 399 | "# l == ['python', 3, 'in', 'one', 'pic']\n", 400 | "\n", 401 | "l.insert(2, '.4.1') # None\n", 402 | "print(l)\n", 403 | "# l == ['python', 3, '.4.1', 'in', 'one', 'pic']\n", 404 | "\n", 405 | "l.extend(['!', '!'])\n", 406 | "print(l)\n", 407 | "# l == ['python', 3, '.4.1', 'in', 'one', 'pic', '!', '!']" 408 | ] 409 | }, 410 | { 411 | "cell_type": "code", 412 | "execution_count": 16, 413 | "metadata": { 414 | "collapsed": false 415 | }, 416 | "outputs": [ 417 | { 418 | "name": "stdout", 419 | "output_type": "stream", 420 | "text": [ 421 | "!\n", 422 | "['python', 3, '.4.1', 'in', 'one', 'pic', '!']\n", 423 | ".4.1\n", 424 | "['python', 3, 'in', 'one', 'pic', '!']\n", 425 | "['python', 3, 'one', 'pic', '!']\n", 426 | "['python', 3, 'pic', '!']\n" 427 | ] 428 | } 429 | ], 430 | "source": [ 431 | "print(l.pop()) # '!'\n", 432 | "print(l)\n", 433 | "# l == ['python', 3, '.4.1', 'in', 'one', 'pic', '!']\n", 434 | "\n", 435 | "print(l.pop(2)) # '.4.1'\n", 436 | "print(l)\n", 437 | "# l == ['python', 3, 'in', 'one', 'pic', '!']\n", 438 | "\n", 439 | "l.remove(\"in\")\n", 440 | "print(l)\n", 441 | "# l == ['python', 3, 'one', 'pic', '!']\n", 442 | "\n", 443 | "del l[2]\n", 444 | "print(l)\n", 445 | "# l == ['python', 3, 'pic', '!']" 446 | ] 447 | }, 448 | { 449 | "cell_type": "code", 450 | "execution_count": 17, 451 | "metadata": { 452 | "collapsed": false 453 | }, 454 | "outputs": [ 455 | { 456 | "name": "stdout", 457 | "output_type": "stream", 458 | "text": [ 459 | "2\n" 460 | ] 461 | } 462 | ], 463 | "source": [ 464 | "print(l.index('pic')) # 2" 465 | ] 466 | }, 467 | { 468 | "cell_type": "markdown", 469 | "metadata": {}, 470 | "source": [ 471 | "#### Tuple" 472 | ] 473 | }, 474 | { 475 | "cell_type": "code", 476 | "execution_count": 18, 477 | "metadata": { 478 | "collapsed": false 479 | }, 480 | "outputs": [ 481 | { 482 | "name": "stdout", 483 | "output_type": "stream", 484 | "text": [ 485 | "\n" 486 | ] 487 | } 488 | ], 489 | "source": [ 490 | "tp = (1, 2, 3, [4, 5])\n", 491 | "print(type(tp)) # " 492 | ] 493 | }, 494 | { 495 | "cell_type": "code", 496 | "execution_count": 19, 497 | "metadata": { 498 | "collapsed": false 499 | }, 500 | "outputs": [ 501 | { 502 | "name": "stdout", 503 | "output_type": "stream", 504 | "text": [ 505 | "4\n", 506 | "3\n", 507 | "(1, 2, 3, [4, 6])\n" 508 | ] 509 | } 510 | ], 511 | "source": [ 512 | "## Length\n", 513 | "print(len(tp)) # 4\n", 514 | "\n", 515 | "print(tp[2]) # 3\n", 516 | "tp[3][1] = 6\n", 517 | "print(tp) # (1, 2, 3, [4, 6])" 518 | ] 519 | }, 520 | { 521 | "cell_type": "code", 522 | "execution_count": 20, 523 | "metadata": { 524 | "collapsed": false 525 | }, 526 | "outputs": [ 527 | { 528 | "name": "stdout", 529 | "output_type": "stream", 530 | "text": [ 531 | "(1,)\n" 532 | ] 533 | } 534 | ], 535 | "source": [ 536 | "## Single element\n", 537 | "tp = (1, ) # Not tp = (1)\n", 538 | "print(tp)" 539 | ] 540 | }, 541 | { 542 | "cell_type": "code", 543 | "execution_count": 21, 544 | "metadata": { 545 | "collapsed": false 546 | }, 547 | "outputs": [ 548 | { 549 | "name": "stdout", 550 | "output_type": "stream", 551 | "text": [ 552 | "a 2 3\n" 553 | ] 554 | } 555 | ], 556 | "source": [ 557 | "## Assign multiple values at once\n", 558 | "v = (3, 2, 'a')\n", 559 | "(c, b, a) = v\n", 560 | "print(a, b, c) # a 2 3" 561 | ] 562 | }, 563 | { 564 | "cell_type": "markdown", 565 | "metadata": {}, 566 | "source": [ 567 | "#### Set" 568 | ] 569 | }, 570 | { 571 | "cell_type": "code", 572 | "execution_count": 22, 573 | "metadata": { 574 | "collapsed": false 575 | }, 576 | "outputs": [ 577 | { 578 | "name": "stdout", 579 | "output_type": "stream", 580 | "text": [ 581 | "\n" 582 | ] 583 | } 584 | ], 585 | "source": [ 586 | "st = {'s', 'e', 'T'}\n", 587 | "print(type(st)) # " 588 | ] 589 | }, 590 | { 591 | "cell_type": "code", 592 | "execution_count": 23, 593 | "metadata": { 594 | "collapsed": false 595 | }, 596 | "outputs": [ 597 | { 598 | "name": "stdout", 599 | "output_type": "stream", 600 | "text": [ 601 | "3\n" 602 | ] 603 | } 604 | ], 605 | "source": [ 606 | "## Length\n", 607 | "print(len(st)) # 3" 608 | ] 609 | }, 610 | { 611 | "cell_type": "code", 612 | "execution_count": 24, 613 | "metadata": { 614 | "collapsed": false 615 | }, 616 | "outputs": [ 617 | { 618 | "name": "stdout", 619 | "output_type": "stream", 620 | "text": [ 621 | "0\n" 622 | ] 623 | } 624 | ], 625 | "source": [ 626 | "## Empty\n", 627 | "st = set()\n", 628 | "print(len(st)) # 0" 629 | ] 630 | }, 631 | { 632 | "cell_type": "code", 633 | "execution_count": 25, 634 | "metadata": { 635 | "collapsed": false 636 | }, 637 | "outputs": [ 638 | { 639 | "name": "stdout", 640 | "output_type": "stream", 641 | "text": [ 642 | "\n" 643 | ] 644 | } 645 | ], 646 | "source": [ 647 | "st = {}\n", 648 | "print(type(st)) # " 649 | ] 650 | }, 651 | { 652 | "cell_type": "code", 653 | "execution_count": 26, 654 | "metadata": { 655 | "collapsed": false 656 | }, 657 | "outputs": [ 658 | { 659 | "name": "stdout", 660 | "output_type": "stream", 661 | "text": [ 662 | "{'!', 'T', 'e', 's', 't'}\n", 663 | "{'e', 's'}\n", 664 | "set()\n" 665 | ] 666 | } 667 | ], 668 | "source": [ 669 | "## Alter\n", 670 | "st = set(['s', 'e', 'T'])\n", 671 | "st.add('t') # st == {'s', 'e', 't', 'T'}\n", 672 | "st.add('t') # st == {'s', 'e', 't', 'T'}\n", 673 | "st.update(['!', '!'])\n", 674 | "print(st)\n", 675 | "# st == {'s', 'e', 't', 'T', '!'}\n", 676 | "\n", 677 | "st.discard('t') # st == {'s', 'e', 'T'}\n", 678 | "st.remove('T') # st == {'s', 'e'}\n", 679 | "st.pop() # 's'\n", 680 | "print(st)\n", 681 | "# st == {'e'}\n", 682 | "\n", 683 | "st.clear() # st == set()\n", 684 | "print(st)" 685 | ] 686 | }, 687 | { 688 | "cell_type": "markdown", 689 | "metadata": {}, 690 | "source": [ 691 | "#### Dict" 692 | ] 693 | }, 694 | { 695 | "cell_type": "code", 696 | "execution_count": 27, 697 | "metadata": { 698 | "collapsed": false 699 | }, 700 | "outputs": [ 701 | { 702 | "name": "stdout", 703 | "output_type": "stream", 704 | "text": [ 705 | "\n", 706 | "{'k1': 'v1', 'k2': 'v2'}\n" 707 | ] 708 | } 709 | ], 710 | "source": [ 711 | "dic = {}\n", 712 | "print(type(dic)) # \n", 713 | "\n", 714 | "dic = {'k1': 'v1', 'k2': 'v2'}\n", 715 | "print(dic)" 716 | ] 717 | }, 718 | { 719 | "cell_type": "code", 720 | "execution_count": 28, 721 | "metadata": { 722 | "collapsed": false 723 | }, 724 | "outputs": [ 725 | { 726 | "name": "stdout", 727 | "output_type": "stream", 728 | "text": [ 729 | "2\n" 730 | ] 731 | } 732 | ], 733 | "source": [ 734 | "## Length\n", 735 | "print(len(dic)) # 2" 736 | ] 737 | }, 738 | { 739 | "cell_type": "code", 740 | "execution_count": 29, 741 | "metadata": { 742 | "collapsed": false 743 | }, 744 | "outputs": [ 745 | { 746 | "name": "stdout", 747 | "output_type": "stream", 748 | "text": [ 749 | "v2\n", 750 | "v1\n", 751 | "v0\n", 752 | "{'k1': 'v1', 'k2': 'v3'}\n", 753 | "True\n", 754 | "False\n" 755 | ] 756 | } 757 | ], 758 | "source": [ 759 | "print(dic['k2']) # 'v2'\n", 760 | "print(dic.get('k1')) # 'v1'\n", 761 | "print(dic.get('k3', 'v0')) # 'v0'\n", 762 | "\n", 763 | "dic['k2'] = 'v3'\n", 764 | "print(dic) # {'k1': 'v1', 'k2': 'v3'}\n", 765 | "\n", 766 | "print('k2' in dic) # True\n", 767 | "print('v1' in dic) # False" 768 | ] 769 | } 770 | ], 771 | "metadata": { 772 | "kernelspec": { 773 | "display_name": "Python 3", 774 | "language": "python", 775 | "name": "python3" 776 | }, 777 | "language_info": { 778 | "codemirror_mode": { 779 | "name": "ipython", 780 | "version": 3 781 | }, 782 | "file_extension": ".py", 783 | "mimetype": "text/x-python", 784 | "name": "python", 785 | "nbconvert_exporter": "python", 786 | "pygments_lexer": "ipython3", 787 | "version": "3.4.1" 788 | } 789 | }, 790 | "nbformat": 4, 791 | "nbformat_minor": 0 792 | } 793 | -------------------------------------------------------------------------------- /notebooks/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siyuanzhao/python3-in-one-pic/893f2e525a7155938313fd402f40279674e7bb42/notebooks/README.md -------------------------------------------------------------------------------- /notebooks/py3-in-one-pic.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": { 7 | "collapsed": false 8 | }, 9 | "outputs": [ 10 | { 11 | "name": "stdout", 12 | "output_type": "stream", 13 | "text": [ 14 | "The Zen of Python, by Tim Peters\n", 15 | "\n", 16 | "Beautiful is better than ugly.\n", 17 | "Explicit is better than implicit.\n", 18 | "Simple is better than complex.\n", 19 | "Complex is better than complicated.\n", 20 | "Flat is better than nested.\n", 21 | "Sparse is better than dense.\n", 22 | "Readability counts.\n", 23 | "Special cases aren't special enough to break the rules.\n", 24 | "Although practicality beats purity.\n", 25 | "Errors should never pass silently.\n", 26 | "Unless explicitly silenced.\n", 27 | "In the face of ambiguity, refuse the temptation to guess.\n", 28 | "There should be one-- and preferably only one --obvious way to do it.\n", 29 | "Although that way may not be obvious at first unless you're Dutch.\n", 30 | "Now is better than never.\n", 31 | "Although never is often better than *right* now.\n", 32 | "If the implementation is hard to explain, it's a bad idea.\n", 33 | "If the implementation is easy to explain, it may be a good idea.\n", 34 | "Namespaces are one honking great idea -- let's do more of those!\n" 35 | ] 36 | } 37 | ], 38 | "source": [ 39 | "import this" 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": {}, 45 | "source": [ 46 | "### I. Native DataTypes\n", 47 | "#### Number" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": 2, 53 | "metadata": { 54 | "collapsed": false 55 | }, 56 | "outputs": [ 57 | { 58 | "name": "stdout", 59 | "output_type": "stream", 60 | "text": [ 61 | "\n" 62 | ] 63 | } 64 | ], 65 | "source": [ 66 | "## integer\n", 67 | "a = 1\n", 68 | "b = 0x10 # 16\n", 69 | "print(type(a)) # " 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 3, 75 | "metadata": { 76 | "collapsed": false 77 | }, 78 | "outputs": [ 79 | { 80 | "name": "stdout", 81 | "output_type": "stream", 82 | "text": [ 83 | "\n" 84 | ] 85 | } 86 | ], 87 | "source": [ 88 | "## float\n", 89 | "c = 1.2\n", 90 | "d = .5 # 0.5\n", 91 | "g = .314e1 # 3.14\n", 92 | "print(type(g)) # " 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 4, 98 | "metadata": { 99 | "collapsed": false 100 | }, 101 | "outputs": [ 102 | { 103 | "name": "stdout", 104 | "output_type": "stream", 105 | "text": [ 106 | "\n", 107 | "True\n" 108 | ] 109 | } 110 | ], 111 | "source": [ 112 | "## complex\n", 113 | "e = 1+2j\n", 114 | "f = complex(1, 2)\n", 115 | "print(type(e)) # \n", 116 | "print(f == e) # True" 117 | ] 118 | }, 119 | { 120 | "cell_type": "markdown", 121 | "metadata": {}, 122 | "source": [ 123 | "#### String" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": 5, 129 | "metadata": { 130 | "collapsed": false 131 | }, 132 | "outputs": [ 133 | { 134 | "name": "stdout", 135 | "output_type": "stream", 136 | "text": [ 137 | "\n", 138 | "🐶\n", 139 | ", Dogge's home, \n", 140 | "Hello,\n", 141 | "Dogge!\n", 142 | "\n" 143 | ] 144 | } 145 | ], 146 | "source": [ 147 | "s1 = '🐶\\n'\n", 148 | "s2 = \"Dogge's home\"\n", 149 | "s3 = \"\"\"\n", 150 | "Hello,\n", 151 | "Dogge!\n", 152 | "\"\"\"\n", 153 | "print(type(s1)) # \n", 154 | "print(\"%s, %s, %s\" % (s1, s2, s3))" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": 6, 160 | "metadata": { 161 | "collapsed": false 162 | }, 163 | "outputs": [ 164 | { 165 | "name": "stdout", 166 | "output_type": "stream", 167 | "text": [ 168 | "2\n" 169 | ] 170 | } 171 | ], 172 | "source": [ 173 | "## Length\n", 174 | "print(len(s1)) # 2" 175 | ] 176 | }, 177 | { 178 | "cell_type": "code", 179 | "execution_count": 7, 180 | "metadata": { 181 | "collapsed": false 182 | }, 183 | "outputs": [ 184 | { 185 | "name": "stdout", 186 | "output_type": "stream", 187 | "text": [ 188 | "学:习\n" 189 | ] 190 | } 191 | ], 192 | "source": [ 193 | "## Slicing\n", 194 | "s = '学而时习之'\n", 195 | "print('{0}:{1}'.format(s[0], s[-2])) # 学:习" 196 | ] 197 | }, 198 | { 199 | "cell_type": "markdown", 200 | "metadata": {}, 201 | "source": [ 202 | "#### Byte" 203 | ] 204 | }, 205 | { 206 | "cell_type": "code", 207 | "execution_count": 8, 208 | "metadata": { 209 | "collapsed": false 210 | }, 211 | "outputs": [ 212 | { 213 | "name": "stdout", 214 | "output_type": "stream", 215 | "text": [ 216 | "\n", 217 | "False\n", 218 | "True\n" 219 | ] 220 | } 221 | ], 222 | "source": [ 223 | "# Byte\n", 224 | "## 0-255/x00-xff\n", 225 | "byt = b'abc'\n", 226 | "print(type(byt)) # \n", 227 | "print(byt[0] == 'a')# False\n", 228 | "print(byt[0] == 97) # True" 229 | ] 230 | }, 231 | { 232 | "cell_type": "code", 233 | "execution_count": 9, 234 | "metadata": { 235 | "collapsed": false 236 | }, 237 | "outputs": [ 238 | { 239 | "name": "stdout", 240 | "output_type": "stream", 241 | "text": [ 242 | "3\n" 243 | ] 244 | } 245 | ], 246 | "source": [ 247 | "## Length\n", 248 | "print(len(byt)) # 3" 249 | ] 250 | }, 251 | { 252 | "cell_type": "markdown", 253 | "metadata": {}, 254 | "source": [ 255 | "#### Boolean" 256 | ] 257 | }, 258 | { 259 | "cell_type": "code", 260 | "execution_count": 10, 261 | "metadata": { 262 | "collapsed": false 263 | }, 264 | "outputs": [ 265 | { 266 | "name": "stdout", 267 | "output_type": "stream", 268 | "text": [ 269 | "\n" 270 | ] 271 | } 272 | ], 273 | "source": [ 274 | "True\n", 275 | "False\n", 276 | "print(type(True)) # " 277 | ] 278 | }, 279 | { 280 | "cell_type": "markdown", 281 | "metadata": {}, 282 | "source": [ 283 | "#### None" 284 | ] 285 | }, 286 | { 287 | "cell_type": "code", 288 | "execution_count": 11, 289 | "metadata": { 290 | "collapsed": false 291 | }, 292 | "outputs": [ 293 | { 294 | "name": "stdout", 295 | "output_type": "stream", 296 | "text": [ 297 | "True\n", 298 | "\n" 299 | ] 300 | } 301 | ], 302 | "source": [ 303 | "print(None is None) # True\n", 304 | "print(type(None)) # " 305 | ] 306 | }, 307 | { 308 | "cell_type": "markdown", 309 | "metadata": {}, 310 | "source": [ 311 | "#### List" 312 | ] 313 | }, 314 | { 315 | "cell_type": "code", 316 | "execution_count": 12, 317 | "metadata": { 318 | "collapsed": false 319 | }, 320 | "outputs": [ 321 | { 322 | "name": "stdout", 323 | "output_type": "stream", 324 | "text": [ 325 | "\n" 326 | ] 327 | } 328 | ], 329 | "source": [ 330 | "l = ['python', 3, 'in', 'one']\n", 331 | "print(type(l)) # " 332 | ] 333 | }, 334 | { 335 | "cell_type": "code", 336 | "execution_count": 13, 337 | "metadata": { 338 | "collapsed": false 339 | }, 340 | "outputs": [ 341 | { 342 | "name": "stdout", 343 | "output_type": "stream", 344 | "text": [ 345 | "4\n" 346 | ] 347 | } 348 | ], 349 | "source": [ 350 | "## Length\n", 351 | "print(len(l)) # 4" 352 | ] 353 | }, 354 | { 355 | "cell_type": "code", 356 | "execution_count": 14, 357 | "metadata": { 358 | "collapsed": false 359 | }, 360 | "outputs": [ 361 | { 362 | "name": "stdout", 363 | "output_type": "stream", 364 | "text": [ 365 | "python\n", 366 | "one\n", 367 | "[3, 'in']\n" 368 | ] 369 | } 370 | ], 371 | "source": [ 372 | "## Slicing\n", 373 | "print(l[0]) # 'python'\n", 374 | "print(l[-1]) # 'one'\n", 375 | "print(l[1:-1]) # [3, 'in']" 376 | ] 377 | }, 378 | { 379 | "cell_type": "code", 380 | "execution_count": 15, 381 | "metadata": { 382 | "collapsed": false 383 | }, 384 | "outputs": [ 385 | { 386 | "name": "stdout", 387 | "output_type": "stream", 388 | "text": [ 389 | "['python', 3, 'in', 'one', 'pic']\n", 390 | "['python', 3, '.4.1', 'in', 'one', 'pic']\n", 391 | "['python', 3, '.4.1', 'in', 'one', 'pic', '!', '!']\n" 392 | ] 393 | } 394 | ], 395 | "source": [ 396 | "## Alter\n", 397 | "l.append('pic') # None\n", 398 | "print(l)\n", 399 | "# l == ['python', 3, 'in', 'one', 'pic']\n", 400 | "\n", 401 | "l.insert(2, '.4.1') # None\n", 402 | "print(l)\n", 403 | "# l == ['python', 3, '.4.1', 'in', 'one', 'pic']\n", 404 | "\n", 405 | "l.extend(['!', '!'])\n", 406 | "print(l)\n", 407 | "# l == ['python', 3, '.4.1', 'in', 'one', 'pic', '!', '!']" 408 | ] 409 | }, 410 | { 411 | "cell_type": "code", 412 | "execution_count": 16, 413 | "metadata": { 414 | "collapsed": false 415 | }, 416 | "outputs": [ 417 | { 418 | "name": "stdout", 419 | "output_type": "stream", 420 | "text": [ 421 | "!\n", 422 | "['python', 3, '.4.1', 'in', 'one', 'pic', '!']\n", 423 | ".4.1\n", 424 | "['python', 3, 'in', 'one', 'pic', '!']\n", 425 | "['python', 3, 'one', 'pic', '!']\n", 426 | "['python', 3, 'pic', '!']\n" 427 | ] 428 | } 429 | ], 430 | "source": [ 431 | "print(l.pop()) # '!'\n", 432 | "print(l)\n", 433 | "# l == ['python', 3, '.4.1', 'in', 'one', 'pic', '!']\n", 434 | "\n", 435 | "print(l.pop(2)) # '.4.1'\n", 436 | "print(l)\n", 437 | "# l == ['python', 3, 'in', 'one', 'pic', '!']\n", 438 | "\n", 439 | "l.remove(\"in\")\n", 440 | "print(l)\n", 441 | "# l == ['python', 3, 'one', 'pic', '!']\n", 442 | "\n", 443 | "del l[2]\n", 444 | "print(l)\n", 445 | "# l == ['python', 3, 'pic', '!']" 446 | ] 447 | }, 448 | { 449 | "cell_type": "code", 450 | "execution_count": 17, 451 | "metadata": { 452 | "collapsed": false 453 | }, 454 | "outputs": [ 455 | { 456 | "name": "stdout", 457 | "output_type": "stream", 458 | "text": [ 459 | "2\n" 460 | ] 461 | } 462 | ], 463 | "source": [ 464 | "print(l.index('pic')) # 2" 465 | ] 466 | }, 467 | { 468 | "cell_type": "markdown", 469 | "metadata": {}, 470 | "source": [ 471 | "#### Tuple" 472 | ] 473 | }, 474 | { 475 | "cell_type": "code", 476 | "execution_count": 18, 477 | "metadata": { 478 | "collapsed": false 479 | }, 480 | "outputs": [ 481 | { 482 | "name": "stdout", 483 | "output_type": "stream", 484 | "text": [ 485 | "\n" 486 | ] 487 | } 488 | ], 489 | "source": [ 490 | "tp = (1, 2, 3, [4, 5])\n", 491 | "print(type(tp)) # " 492 | ] 493 | }, 494 | { 495 | "cell_type": "code", 496 | "execution_count": 19, 497 | "metadata": { 498 | "collapsed": false 499 | }, 500 | "outputs": [ 501 | { 502 | "name": "stdout", 503 | "output_type": "stream", 504 | "text": [ 505 | "4\n", 506 | "3\n", 507 | "(1, 2, 3, [4, 6])\n" 508 | ] 509 | } 510 | ], 511 | "source": [ 512 | "## Length\n", 513 | "print(len(tp)) # 4\n", 514 | "\n", 515 | "print(tp[2]) # 3\n", 516 | "tp[3][1] = 6\n", 517 | "print(tp) # (1, 2, 3, [4, 6])" 518 | ] 519 | }, 520 | { 521 | "cell_type": "code", 522 | "execution_count": 20, 523 | "metadata": { 524 | "collapsed": false 525 | }, 526 | "outputs": [ 527 | { 528 | "name": "stdout", 529 | "output_type": "stream", 530 | "text": [ 531 | "(1,)\n" 532 | ] 533 | } 534 | ], 535 | "source": [ 536 | "## Single element\n", 537 | "tp = (1, ) # Not tp = (1)\n", 538 | "print(tp)" 539 | ] 540 | }, 541 | { 542 | "cell_type": "code", 543 | "execution_count": 21, 544 | "metadata": { 545 | "collapsed": false 546 | }, 547 | "outputs": [ 548 | { 549 | "name": "stdout", 550 | "output_type": "stream", 551 | "text": [ 552 | "a 2 3\n" 553 | ] 554 | } 555 | ], 556 | "source": [ 557 | "## Assign multiple values at once\n", 558 | "v = (3, 2, 'a')\n", 559 | "(c, b, a) = v\n", 560 | "print(a, b, c) # a 2 3" 561 | ] 562 | }, 563 | { 564 | "cell_type": "markdown", 565 | "metadata": {}, 566 | "source": [ 567 | "#### Set" 568 | ] 569 | }, 570 | { 571 | "cell_type": "code", 572 | "execution_count": 22, 573 | "metadata": { 574 | "collapsed": false 575 | }, 576 | "outputs": [ 577 | { 578 | "name": "stdout", 579 | "output_type": "stream", 580 | "text": [ 581 | "\n" 582 | ] 583 | } 584 | ], 585 | "source": [ 586 | "st = {'s', 'e', 'T'}\n", 587 | "print(type(st)) # " 588 | ] 589 | }, 590 | { 591 | "cell_type": "code", 592 | "execution_count": 23, 593 | "metadata": { 594 | "collapsed": false 595 | }, 596 | "outputs": [ 597 | { 598 | "name": "stdout", 599 | "output_type": "stream", 600 | "text": [ 601 | "3\n" 602 | ] 603 | } 604 | ], 605 | "source": [ 606 | "## Length\n", 607 | "print(len(st)) # 3" 608 | ] 609 | }, 610 | { 611 | "cell_type": "code", 612 | "execution_count": 24, 613 | "metadata": { 614 | "collapsed": false 615 | }, 616 | "outputs": [ 617 | { 618 | "name": "stdout", 619 | "output_type": "stream", 620 | "text": [ 621 | "0\n" 622 | ] 623 | } 624 | ], 625 | "source": [ 626 | "## Empty\n", 627 | "st = set()\n", 628 | "print(len(st)) # 0" 629 | ] 630 | }, 631 | { 632 | "cell_type": "code", 633 | "execution_count": 25, 634 | "metadata": { 635 | "collapsed": false 636 | }, 637 | "outputs": [ 638 | { 639 | "name": "stdout", 640 | "output_type": "stream", 641 | "text": [ 642 | "\n" 643 | ] 644 | } 645 | ], 646 | "source": [ 647 | "st = {}\n", 648 | "print(type(st)) # " 649 | ] 650 | }, 651 | { 652 | "cell_type": "code", 653 | "execution_count": 26, 654 | "metadata": { 655 | "collapsed": false 656 | }, 657 | "outputs": [ 658 | { 659 | "name": "stdout", 660 | "output_type": "stream", 661 | "text": [ 662 | "{'!', 'T', 'e', 's', 't'}\n", 663 | "{'e', 's'}\n", 664 | "set()\n" 665 | ] 666 | } 667 | ], 668 | "source": [ 669 | "## Alter\n", 670 | "st = set(['s', 'e', 'T'])\n", 671 | "st.add('t') # st == {'s', 'e', 't', 'T'}\n", 672 | "st.add('t') # st == {'s', 'e', 't', 'T'}\n", 673 | "st.update(['!', '!'])\n", 674 | "print(st)\n", 675 | "# st == {'s', 'e', 't', 'T', '!'}\n", 676 | "\n", 677 | "st.discard('t') # st == {'s', 'e', 'T'}\n", 678 | "st.remove('T') # st == {'s', 'e'}\n", 679 | "st.pop() # 's'\n", 680 | "print(st)\n", 681 | "# st == {'e'}\n", 682 | "\n", 683 | "st.clear() # st == set()\n", 684 | "print(st)" 685 | ] 686 | }, 687 | { 688 | "cell_type": "markdown", 689 | "metadata": {}, 690 | "source": [ 691 | "#### Dict" 692 | ] 693 | }, 694 | { 695 | "cell_type": "code", 696 | "execution_count": 2, 697 | "metadata": { 698 | "collapsed": false 699 | }, 700 | "outputs": [ 701 | { 702 | "name": "stdout", 703 | "output_type": "stream", 704 | "text": [ 705 | "\n", 706 | "{'k2': 'v2', 'k1': 'v1'}\n" 707 | ] 708 | } 709 | ], 710 | "source": [ 711 | "dic = {}\n", 712 | "print(type(dic)) # \n", 713 | "\n", 714 | "dic = {'k1': 'v1', 'k2': 'v2'}\n", 715 | "print(dic)" 716 | ] 717 | }, 718 | { 719 | "cell_type": "code", 720 | "execution_count": 3, 721 | "metadata": { 722 | "collapsed": false 723 | }, 724 | "outputs": [ 725 | { 726 | "name": "stdout", 727 | "output_type": "stream", 728 | "text": [ 729 | "2\n" 730 | ] 731 | } 732 | ], 733 | "source": [ 734 | "## Length\n", 735 | "print(len(dic)) # 2" 736 | ] 737 | }, 738 | { 739 | "cell_type": "code", 740 | "execution_count": 4, 741 | "metadata": { 742 | "collapsed": false 743 | }, 744 | "outputs": [ 745 | { 746 | "name": "stdout", 747 | "output_type": "stream", 748 | "text": [ 749 | "v2\n", 750 | "v1\n", 751 | "v0\n", 752 | "{'k2': 'v3', 'k1': 'v1'}\n", 753 | "True\n", 754 | "False\n" 755 | ] 756 | } 757 | ], 758 | "source": [ 759 | "print(dic['k2']) # 'v2'\n", 760 | "print(dic.get('k1')) # 'v1'\n", 761 | "print(dic.get('k3', 'v0')) # 'v0'\n", 762 | "\n", 763 | "dic['k2'] = 'v3'\n", 764 | "print(dic) # {'k1': 'v1', 'k2': 'v3'}\n", 765 | "\n", 766 | "print('k2' in dic) # True\n", 767 | "print('v1' in dic) # False" 768 | ] 769 | }, 770 | { 771 | "cell_type": "markdown", 772 | "metadata": {}, 773 | "source": [ 774 | "### II. Operators & Casting\n", 775 | "\n", 776 | "### III. Flow Control\n", 777 | "\n", 778 | "#### If" 779 | ] 780 | }, 781 | { 782 | "cell_type": "code", 783 | "execution_count": 6, 784 | "metadata": { 785 | "collapsed": false 786 | }, 787 | "outputs": [ 788 | { 789 | "name": "stdout", 790 | "output_type": "stream", 791 | "text": [ 792 | "Version 3.X\n" 793 | ] 794 | } 795 | ], 796 | "source": [ 797 | "import sys\n", 798 | "if sys.version_info.major < 3:\n", 799 | " print(\"Version 2.X\")\n", 800 | "elif sys.version_info.major > 3:\n", 801 | " print(\"Future\")\n", 802 | "else:\n", 803 | " print(\"Version 3.X\")" 804 | ] 805 | }, 806 | { 807 | "cell_type": "markdown", 808 | "metadata": {}, 809 | "source": [ 810 | "#### Loop" 811 | ] 812 | }, 813 | { 814 | "cell_type": "markdown", 815 | "metadata": {}, 816 | "source": [ 817 | "**for**" 818 | ] 819 | }, 820 | { 821 | "cell_type": "code", 822 | "execution_count": 7, 823 | "metadata": { 824 | "collapsed": false 825 | }, 826 | "outputs": [ 827 | { 828 | "name": "stdout", 829 | "output_type": "stream", 830 | "text": [ 831 | "H\n", 832 | "e\n", 833 | "l\n", 834 | "l\n", 835 | "o\n" 836 | ] 837 | } 838 | ], 839 | "source": [ 840 | "for i in \"Hello\":\n", 841 | " print(i)" 842 | ] 843 | }, 844 | { 845 | "cell_type": "markdown", 846 | "metadata": {}, 847 | "source": [ 848 | "**while**" 849 | ] 850 | }, 851 | { 852 | "cell_type": "code", 853 | "execution_count": 8, 854 | "metadata": { 855 | "collapsed": false 856 | }, 857 | "outputs": [ 858 | { 859 | "name": "stdout", 860 | "output_type": "stream", 861 | "text": [ 862 | "362880\n" 863 | ] 864 | } 865 | ], 866 | "source": [ 867 | "prod = 1\n", 868 | "i = 1\n", 869 | "while i < 10:\n", 870 | " prod = prod * i\n", 871 | " i += 1\n", 872 | "print(prod)" 873 | ] 874 | }, 875 | { 876 | "cell_type": "markdown", 877 | "metadata": {}, 878 | "source": [ 879 | "### IV. Function\n", 880 | "\n", 881 | "### V. Class\n", 882 | "\n", 883 | "### VI. Module\n", 884 | "\n", 885 | "### VII. Pythonic\n", 886 | "\n", 887 | "### VIII. Standard Libraries" 888 | ] 889 | }, 890 | { 891 | "cell_type": "code", 892 | "execution_count": null, 893 | "metadata": { 894 | "collapsed": true 895 | }, 896 | "outputs": [], 897 | "source": [] 898 | } 899 | ], 900 | "metadata": { 901 | "kernelspec": { 902 | "display_name": "Python 3", 903 | "language": "python", 904 | "name": "python3" 905 | }, 906 | "language_info": { 907 | "codemirror_mode": { 908 | "name": "ipython", 909 | "version": 3 910 | }, 911 | "file_extension": ".py", 912 | "mimetype": "text/x-python", 913 | "name": "python", 914 | "nbconvert_exporter": "python", 915 | "pygments_lexer": "ipython3", 916 | "version": "3.4.1" 917 | } 918 | }, 919 | "nbformat": 4, 920 | "nbformat_minor": 0 921 | } 922 | -------------------------------------------------------------------------------- /py3 in one pic.mindnode/QuickLook/Preview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siyuanzhao/python3-in-one-pic/893f2e525a7155938313fd402f40279674e7bb42/py3 in one pic.mindnode/QuickLook/Preview.jpg -------------------------------------------------------------------------------- /py3 in one pic.mindnode/style.mindnodestyle/contents.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siyuanzhao/python3-in-one-pic/893f2e525a7155938313fd402f40279674e7bb42/py3 in one pic.mindnode/style.mindnodestyle/contents.xml -------------------------------------------------------------------------------- /py3 in one pic.mindnode/style.mindnodestyle/metadata.plist: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siyuanzhao/python3-in-one-pic/893f2e525a7155938313fd402f40279674e7bb42/py3 in one pic.mindnode/style.mindnodestyle/metadata.plist -------------------------------------------------------------------------------- /py3 in one pic.mindnode/viewState.plist: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siyuanzhao/python3-in-one-pic/893f2e525a7155938313fd402f40279674e7bb42/py3 in one pic.mindnode/viewState.plist -------------------------------------------------------------------------------- /py3 in one pic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siyuanzhao/python3-in-one-pic/893f2e525a7155938313fd402f40279674e7bb42/py3 in one pic.png -------------------------------------------------------------------------------- /src/basicSyntax.py: -------------------------------------------------------------------------------- 1 | # Case-sensitive 2 | a = 1 3 | A = 2 4 | print(a is not A) # True 5 | 6 | # Comments will be ignored 7 | 8 | # Code blocks are defined by their indentation 9 | # Use 4 spaces per indentation level. 10 | -------------------------------------------------------------------------------- /src/nativeDatatypes.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # Number 4 | ## integer 5 | a = 1 6 | b = 0x10 # 16 7 | c = 0o10 # 8 8 | d = 0b10 # 2 9 | print(type(a)) # 10 | 11 | ## float 12 | c = 1.2 13 | d = .5 # 0.5 14 | g = .314e1 # 3.14 15 | print(type(g)) # 16 | 17 | ## complex 18 | e = 1+2j 19 | f = complex(1, 2) 20 | print(type(e)) # 21 | print(f == e) # True 22 | 23 | # String 24 | s1 = '🐶\n' 25 | s2 = "Dogge's home" 26 | s3 = """ 27 | Hello, 28 | Dogge! 29 | """ 30 | print(type(s1)) # 31 | print("%s, %s, %s" % (s1, s2, s3)) 32 | # 🐶 33 | # , Dogge's home, 34 | # Hello, 35 | # Dogge! 36 | 37 | ## Length 38 | print(len(s1)) # 2 39 | 40 | ## Slicing 41 | s = '学而时习之' 42 | print('{0}:{1}'.format(s[0], s[-2])) # 学:习 43 | 44 | # Byte 45 | ## 0-255/x00-xff 46 | byt = b'abc' 47 | print(type(byt)) # 48 | print(byt[0] == 'a')# False 49 | print(byt[0] == 97) # True 50 | 51 | ## Length 52 | print(len(byt)) # 3 53 | 54 | # Boolean 55 | True 56 | False 57 | print(type(True)) # 58 | 59 | # None 60 | print(None is None) # True 61 | print(type(None)) # 62 | 63 | # List 64 | l = ['python', 3, 'in', 'one'] 65 | print(type(l)) # 66 | 67 | ## Length 68 | print(len(l)) # 4 69 | 70 | ## Slicing 71 | print(l[0]) # 'python' 72 | print(l[-1]) # 'one' 73 | print(l[1:-1]) # [3, 'in'] 74 | 75 | ## Alter 76 | l.append('pic') # None 77 | # l == ['python', 3, 'in', 'one', 'pic'] 78 | l.insert(2, '.4.1') # None 79 | # l == ['python', 3, '.4.1', 'in', 'one', 'pic'] 80 | l.extend(['!', '!']) 81 | # l == ['python', 3, '.4.1', 'in', 'one', 'pic', '!', '!'] 82 | 83 | 84 | print(l.pop()) # '!' 85 | # l == ['python', 3, '.4.1', 'in', 'one', 'pic', '!'] 86 | print(l.pop(2)) # '.4.1' 87 | # l == ['python', 3, 'in', 'one', 'pic', '!'] 88 | l.remove("in") 89 | # l == ['python', 3, 'one', 'pic', '!'] 90 | del l[2] 91 | # l == ['python', 3, 'pic', '!'] 92 | 93 | print(l.index('pic')) # 2 94 | 95 | # Tuple 96 | tp = (1, 2, 3, [4, 5]) 97 | print(type(tp)) # 98 | 99 | ## Length 100 | print(len(tp)) # 4 101 | 102 | print(tp[2]) # 3 103 | tp[3][1] = 6 104 | print(tp) # (1, 2, 3, [4, 6]) 105 | 106 | ## Single element 107 | tp = (1, ) # Not tp = (1) 108 | 109 | ## Assign multiple values at once 110 | v = (3, 2, 'a') 111 | (c, b, a) = v 112 | print(a, b, c) # a 2 3 113 | 114 | # Set 115 | st = {'s', 'e', 'T'} 116 | print(type(st)) # 117 | 118 | ## Length 119 | print(len(st)) # 3 120 | 121 | ## Empty 122 | st = set() 123 | print(len(st)) # 0 124 | 125 | st = {} 126 | print(type(st)) # 127 | 128 | ## Alter 129 | st = set(['s', 'e', 'T']) 130 | st.add('t') # st == {'s', 'e', 't', 'T'} 131 | st.add('t') # st == {'s', 'e', 't', 'T'} 132 | st.update(['!', '!']) 133 | # st == {'s', 'e', 't', 'T', '!'} 134 | 135 | st.discard('t') # st == {'s', 'e', 'T'} 136 | st.remove('T') # st == {'s', 'e'} 137 | st.pop() # 's' 138 | # st == {'e'} 139 | 140 | st.clear() # st == set() 141 | 142 | # Dict 143 | dic = {} 144 | print(type(dic)) # 145 | 146 | dic = {'k1': 'v1', 'k2': 'v2'} 147 | 148 | ## Length 149 | print(len(dic)) # 2 150 | 151 | 152 | print(dic['k2']) # 'v2' 153 | print(dic.get('k1')) # 'v1' 154 | print(dic.get('k3', 'v0')) # 'v0' 155 | 156 | dic['k2'] = 'v3' 157 | print(dic) # {'k1': 'v1', 'k2': 'v3'} 158 | 159 | print('k2' in dic) # True 160 | print('v1' in dic) # False 161 | -------------------------------------------------------------------------------- /src/this.py: -------------------------------------------------------------------------------- 1 | import this 2 | --------------------------------------------------------------------------------