Beginning Python - From Novice to Professional
Beginning Python - From Novice to Professional Beginning Python - From Novice to Professional
APPENDIX B ■ ■ ■ Python Reference This is not a full Python reference by far—you can find that in the standard Python documentation (http://python.org/doc/ref). Rather, this is a handy “cheat sheet” that can be useful for refreshing your memory as you start out programming in Python. Expressions This section summarizes Python expressions. Table B-1 lists the most important basic (literal) values in Python; Table B-2 lists the Python operators, along with their precedence (those with high precedence are evaluated before those with low precedence); Table B-3 describes some of the most important built-in functions; Tables B-4 through B-6 describe the list methods, dictionary methods, and string methods, respectively. Table B-1. Basic (Literal) Values Type Description Syntax Samples Integer Numbers without a fractional part 42 Long integer Large integer numbers 42L Float Numbers with a fractional part 42.5, 42.5e-2 Complex Sum of a real (integer or float) and imaginary number 38 + 4j, 42j String An immutable sequence of characters 'foo', "bar", """baz""", r'\n' Unicode An immutable sequence of Unicode characters u'foo', u"bar", u"""baz""" 557
558 APPENDIX B ■ PYTHON REFERENCE Table B-2. Operators Operator Description Precedence lambda Lambda expression 1 or Logical or 2 and Logical and 3 not Logical negation 4 in Membership test 5 not in Negative membership test 5 is Identity test 6 is not Negative identity test 6 < Less than 7 > Greater than 7 = Greater than or equal to 7 == Equal to 7 != Not equal to 7 | Bitwise or 8 ^ Bitwise exclusive or 9 & Bitwise and 10 > Right shift 11 + Addition 12 - Subtraction 12 * Multiplication 13 / Division 13 % Remainder 13 + Unary identity 14 - Unary negation 14 ~ Bitwise complement 15 ** Exponentiation 16 x.attribute Attribute reference 17 x[index] Subscription 18 x[index1:index2[:index3]] Slicing 19 f(args...) Function call 20
- Page 537 and 538: 506 CHAPTER 27 ■ PROJECT 8: FILE
- Page 539 and 540: 508 CHAPTER 27 ■ PROJECT 8: FILE
- Page 541 and 542: 510 CHAPTER 27 ■ PROJECT 8: FILE
- Page 543 and 544: 512 CHAPTER 27 ■ PROJECT 8: FILE
- Page 545 and 546: 514 CHAPTER 27 ■ PROJECT 8: FILE
- Page 547 and 548: 516 CHAPTER 27 ■ PROJECT 8: FILE
- Page 549 and 550: 518 CHAPTER 28 ■ PROJECT 9: FILE
- Page 551 and 552: 520 CHAPTER 28 ■ PROJECT 9: FILE
- Page 553 and 554: 522 CHAPTER 28 ■ PROJECT 9: FILE
- Page 555 and 556: 524 CHAPTER 28 ■ PROJECT 9: FILE
- Page 558 and 559: CHAPTER 29 ■ ■ ■ Project 10:
- Page 560 and 561: CHAPTER 29 ■ PROJECT 10: DO-IT-YO
- Page 562 and 563: CHAPTER 29 ■ PROJECT 10: DO-IT-YO
- Page 564 and 565: CHAPTER 29 ■ PROJECT 10: DO-IT-YO
- Page 566 and 567: CHAPTER 29 ■ PROJECT 10: DO-IT-YO
- Page 568 and 569: CHAPTER 29 ■ PROJECT 10: DO-IT-YO
- Page 570 and 571: CHAPTER 29 ■ PROJECT 10: DO-IT-YO
- Page 572 and 573: CHAPTER 29 ■ PROJECT 10: DO-IT-YO
- Page 574 and 575: CHAPTER 29 ■ PROJECT 10: DO-IT-YO
- Page 576 and 577: CHAPTER 29 ■ PROJECT 10: DO-IT-YO
- Page 578 and 579: APPENDIX A ■ ■ ■ The Short Ve
- Page 580 and 581: APPENDIX A ■ THE SHORT VERSION 54
- Page 582 and 583: APPENDIX A ■ THE SHORT VERSION 55
- Page 584 and 585: APPENDIX A ■ THE SHORT VERSION 55
- Page 586: APPENDIX A ■ THE SHORT VERSION 55
- Page 591 and 592: 560 APPENDIX B ■ PYTHON REFERENCE
- Page 593 and 594: 562 APPENDIX B ■ PYTHON REFERENCE
- Page 595 and 596: 564 APPENDIX B ■ PYTHON REFERENCE
- Page 597 and 598: 566 APPENDIX B ■ PYTHON REFERENCE
- Page 599 and 600: 568 APPENDIX B ■ PYTHON REFERENCE
- Page 601 and 602: 570 APPENDIX B ■ PYTHON REFERENCE
- Page 603 and 604: 572 APPENDIX C ■ ONLINE RESOURCES
- Page 606 and 607: Index ■Symbols - operator 558 !=
- Page 608 and 609: ■INDEX 577 assertEqual method Tes
- Page 610 and 611: ■INDEX 579 cmd module 252, 501 Cm
- Page 612 and 613: ■INDEX 581 get method 74-75 has_k
- Page 614 and 615: ■INDEX 583 ■F Factory class twi
- Page 616 and 617: ■INDEX 585 finding conflicts 197
- Page 618 and 619: ■INDEX 587 initialization 38 nami
- Page 620 and 621: ■INDEX 589 localtime function tim
- Page 622 and 623: ■INDEX 591 nesting blocks 88 Netw
- Page 624 and 625: ■INDEX 593 playful programming 38
- Page 626 and 627: ■INDEX 595 Python C API 365 hand-
- Page 628 and 629: ■INDEX 597 ■S safe_substitute m
- Page 630 and 631: ■INDEX 599 split function re modu
- Page 632 and 633: ■INDEX 601 TestCase class methods
- Page 634 and 635: ■INDEX 603 further exploration 47
APPENDIX B<br />
■ ■ ■<br />
<strong>Python</strong> Reference<br />
This is not a full <strong>Python</strong> reference by far—you can find that in the standard <strong>Python</strong> documentation<br />
(http://python.org/doc/ref). Rather, this is a handy “cheat sheet” that can be useful for<br />
refreshing your memory as you start out programming in <strong>Python</strong>.<br />
Expressions<br />
This section summarizes <strong>Python</strong> expressions. Table B-1 lists the most important basic (literal)<br />
values in <strong>Python</strong>; Table B-2 lists the <strong>Python</strong> opera<strong>to</strong>rs, along with their precedence (those with<br />
high precedence are evaluated before those with low precedence); Table B-3 describes some of<br />
the most important built-in functions; Tables B-4 through B-6 describe the list methods,<br />
dictionary methods, and string methods, respectively.<br />
Table B-1. Basic (Literal) Values<br />
Type Description Syntax Samples<br />
Integer Numbers without a fractional part 42<br />
Long integer Large integer numbers 42L<br />
Float Numbers with a fractional part 42.5, 42.5e-2<br />
Complex<br />
Sum of a real (integer or float) and<br />
imaginary number<br />
38 + 4j, 42j<br />
String An immutable sequence of characters 'foo', "bar", """baz""", r'\n'<br />
Unicode<br />
An immutable sequence of Unicode<br />
characters<br />
u'foo', u"bar", u"""baz"""<br />
557