|
1 | 1 | { |
2 | 2 | "metadata": { |
3 | 3 | "name": "", |
4 | | - "signature": "sha256:7eaf1c17c09445d2807a0560a73437a138201e67de0b44e98b6c853eff059061" |
| 4 | + "signature": "sha256:6f669267e7ec7d07f6bd0ac72d891bdb4881c22c9396efcc19ca5bff94903cf9" |
5 | 5 | }, |
6 | 6 | "nbformat": 3, |
7 | 7 | "nbformat_minor": 0, |
|
44 | 44 | "- [Shallow vs. deep copies if list contains other structures and objects](#shallow_vs_deep)\n", |
45 | 45 | "- [Picking True values from and and or expressions](#false_true_expressions)\n", |
46 | 46 | "- [Don't use mutable objects as default arguments for functions!](#def_mutable_func)\n", |
47 | | - "- [Be aware of the consuming generator](#consuming_generator)" |
| 47 | + "- [Be aware of the consuming generator](#consuming_generator)\n", |
| 48 | + "- [`bool` is a subclass of `int`](#bool_int)" |
48 | 49 | ] |
49 | 50 | }, |
50 | 51 | { |
|
420 | 421 | ], |
421 | 422 | "prompt_number": 9 |
422 | 423 | }, |
| 424 | + { |
| 425 | + "cell_type": "markdown", |
| 426 | + "metadata": {}, |
| 427 | + "source": [ |
| 428 | + "And a fun fact" |
| 429 | + ] |
| 430 | + }, |
423 | 431 | { |
424 | 432 | "cell_type": "markdown", |
425 | 433 | "metadata": {}, |
|
535 | 543 | ], |
536 | 544 | "prompt_number": 10 |
537 | 545 | }, |
| 546 | + { |
| 547 | + "cell_type": "markdown", |
| 548 | + "metadata": {}, |
| 549 | + "source": [ |
| 550 | + "<br>\n", |
| 551 | + "<br>\n", |
| 552 | + "<a name='bool_int'></a>\n", |
| 553 | + "\n", |
| 554 | + "## `bool` is a subclass of `int`\n", |
| 555 | + "\n", |
| 556 | + "Chicken or egg? In the history of Python (Python 2.2 to be specific) truth values were implemented via 1 and 0 (similar to the old C), to avoid syntax error in old (but perfectly working) code, `bool` was added as a subclass of `int` in Python 2.3.\n", |
| 557 | + "\n", |
| 558 | + "Original source: [http://www.peterbe.com/plog/bool-is-int](http://www.peterbe.com/plog/bool-is-int)" |
| 559 | + ] |
| 560 | + }, |
| 561 | + { |
| 562 | + "cell_type": "code", |
| 563 | + "collapsed": false, |
| 564 | + "input": [ |
| 565 | + "print('isinstance(True, int):', isinstance(True, int))\n", |
| 566 | + "print('True + True:', True + True)\n", |
| 567 | + "print('3*True:', 3*True)\n", |
| 568 | + "print('3*True - False:', 3*True - False)\n" |
| 569 | + ], |
| 570 | + "language": "python", |
| 571 | + "metadata": {}, |
| 572 | + "outputs": [ |
| 573 | + { |
| 574 | + "output_type": "stream", |
| 575 | + "stream": "stdout", |
| 576 | + "text": [ |
| 577 | + "isinstance(True, int): True\n", |
| 578 | + "True + True: 2\n", |
| 579 | + "3*True: 3\n", |
| 580 | + "3*True - False: 3\n" |
| 581 | + ] |
| 582 | + } |
| 583 | + ], |
| 584 | + "prompt_number": 16 |
| 585 | + }, |
538 | 586 | { |
539 | 587 | "cell_type": "code", |
540 | 588 | "collapsed": false, |
|
0 commit comments