Beginning Python - From Novice to Professional
Beginning Python - From Novice to Professional Beginning Python - From Novice to Professional
APPENDIX B ■ PYTHON REFERENCE 563 Table B-5. Dictionary Methods (Continued) Method dict.has_key(key) dict.items() dict.iteritems() dict.iterkeys() dict.itervalues() dict.keys() dict.pop(key) dict.popitem() dict.setdefault(key[, default]) dict.update(other) dict.values() Description Checks whether dict has the given key. Returns a list of (key, value) pairs representing the items of dict. Returns an iterable object over the same (key, value) pairs as returned by dict.items. Returns an iterable object over the keys of dict. Returns an iterable object over the values of dict. Returns a list of the keys of dict. Removes and returns the value corresponding to the given key. Removes an arbitrary item from dict and returns it as a (key, value) pair. Returns dict[key] if it exists; otherwise it returns the given default value (default None) and binds dict[key] to it. For each item in other, adds the item to dict (possibly overwriting existing items). Can also be called with arguments similar to the dictionary constructor, dict. Returns a list of the values in dict (possibly containing duplicates). Table B-6. String Methods Method string.capitalize() string.center(width[, fillchar]) string.count(sub[, start[, end]]) string.decode([encoding[, errors]]) string.encode([encoding[, errors]]) Description Returns a copy of the string in which the first character is capitalized Returns a string of length max(len(string), width) in which a copy of string is centered, padded with fillchar (default is space) Counts the occurrences of the substring sub, optionally restricting the search to string[start:end] Returns decoded version of the string using the given encoding, handling errors as specified by errors ('strict', 'ignore', or 'replace') Returns encoded version of the string using the given encoding, handling errors as specified by errors ('strict', 'ignore', or 'replace')
564 APPENDIX B ■ PYTHON REFERENCE Table B-6. String Methods (Continued) Method string.endswith(suffix[, start[, end]]) string.expandtabs([tabsize]) string.find(sub[, start[, end]]) string.index(sub[, start[, end]]) string.isalnum() string.isalpha() string.isdigit() string.islower() string.isspace() string.istitle() string.isupper() string.join(sequence) string.ljust(width[, fillchar]) string.lower() string.lstrip([chars]) Description Checks whether string ends with suffix, optionally restricting the matching with the given indices start and end Returns a copy of the string in which tab characters have been expanded using spaces, optionally using the given tabsize (default 8) Returns the first index where the substring sub is found, or –1 if no such index exists, optionally restricting the search to string[start:end] Returns the first index where the substring sub is found, or raises a ValueError if no such index exists, optionally restricting the search to string[start:end] Checks whether the string consists of alphanumeric characters Checks whether the string consists of alphabetic characters Checks whether the string consists of digits Checks whether all the case-based characters (letters) of the string are lowercase Checks whether the string consists of whitespace Checks whether all the case-based characters in the string following non-casebased letters are uppercase and all other case-based characters are lowercase Checks whether all the case-based characters of the string are uppercase Returns a string in which the string elements of sequence have been joined by string Returns a string of length max(len(string), width) in which a copy of string is left justified, padded with fillchar (default is space) Returns a copy of the string in which all case-based characters have been lowercased Returns a copy of the string in which all chars have been stripped from the beginning of the string (default whitespace characters)
- 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 589 and 590: 558 APPENDIX B ■ PYTHON REFERENCE
- Page 591 and 592: 560 APPENDIX B ■ PYTHON REFERENCE
- Page 593: 562 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
- Page 641: forums.apress.com FOR PROFESSIONALS
APPENDIX B ■ PYTHON REFERENCE 563<br />
Table B-5. Dictionary Methods (Continued)<br />
Method<br />
dict.has_key(key)<br />
dict.items()<br />
dict.iteritems()<br />
dict.iterkeys()<br />
dict.itervalues()<br />
dict.keys()<br />
dict.pop(key)<br />
dict.popitem()<br />
dict.setdefault(key[, default])<br />
dict.update(other)<br />
dict.values()<br />
Description<br />
Checks whether dict has the given key.<br />
Returns a list of (key, value) pairs representing the<br />
items of dict.<br />
Returns an iterable object over the same (key, value)<br />
pairs as returned by dict.items.<br />
Returns an iterable object over the keys of dict.<br />
Returns an iterable object over the values of dict.<br />
Returns a list of the keys of dict.<br />
Removes and returns the value corresponding <strong>to</strong> the<br />
given key.<br />
Removes an arbitrary item from dict and returns it as<br />
a (key, value) pair.<br />
Returns dict[key] if it exists; otherwise it returns the<br />
given default value (default None) and binds dict[key]<br />
<strong>to</strong> it.<br />
For each item in other, adds the item <strong>to</strong> dict (possibly<br />
overwriting existing items). Can also be called with<br />
arguments similar <strong>to</strong> the dictionary construc<strong>to</strong>r, dict.<br />
Returns a list of the values in dict (possibly containing<br />
duplicates).<br />
Table B-6. String Methods<br />
Method<br />
string.capitalize()<br />
string.center(width[, fillchar])<br />
string.count(sub[, start[, end]])<br />
string.decode([encoding[, errors]])<br />
string.encode([encoding[, errors]])<br />
Description<br />
Returns a copy of the string in which the<br />
first character is capitalized<br />
Returns a string of length max(len(string),<br />
width) in which a copy of string is centered,<br />
padded with fillchar (default is space)<br />
Counts the occurrences of the substring<br />
sub, optionally restricting the search <strong>to</strong><br />
string[start:end]<br />
Returns decoded version of the string using<br />
the given encoding, handling errors as<br />
specified by errors ('strict', 'ignore',<br />
or 'replace')<br />
Returns encoded version of the string using<br />
the given encoding, handling errors as<br />
specified by errors ('strict', 'ignore', or<br />
'replace')