Supercharged Python: Take Your Code to the Next Level
Book information
Description
Tapping into the full power of Python doesn’t have to be difficult. Supercharged Python is written for people who’ve learned the fundamentals of the language but want to take their skills to the next level. Using the example-driven approach featured in Python Without Fear, Brian Overland and John Bennett start with simple examples and carefully build more complex applications. After briefly reviewing the fundamental concepts of Python, the authors carefully explain more advanced topics, including text formatting, regular expressions, and chart plotting. The book reviews advanced techniques for list and string classes, and then covers all the ways of handling text and binary files; decimal, money, and other special classes; advanced techniques for writing classes; generators and decorators; and the random, math, and Numpy (Numeric Python) packages, which can supercharge your applications. - Use profilers and “magic methods” to code like a pro - Harness the power of regular expressions to process text quickly with a single statement - Take advantage of 22 coding shortcuts, along with performance tips to save time and optimize your code - Create really useful classes and objects, for games, simulations, money, mathematics, and more - Use multiple modules to build powerful apps while avoiding the “gotchas” - Import packages to dramatically speed up statistical operations—by as much as 100 times! - Refer to the five-part language reference to look up fine points of the language Supercharged Python demonstrates techniques that allow you to write faster and more powerful code, whether you’re manipulating large amounts of data or building sophisticated applications. Cover Title Page Copyright Page Contents Preface What Makes Python Special? Paths to Learning: Where Do I Start? Clarity and Examples Are Everything Learning Aids: Icons What You’ll Learn Have Fun Acknowledgments About the Authors Chapter 1 Review of the Fundamentals ____1.1 Python Quick Start ____1.2 Variables and Naming Names ____1.3 Combined Assignment Operators ____1.4 Summary of Python Arithmetic Operators ____1.5 Elementary Data Types: Integer and Floating Point ____1.6 Basic Input and Output ____1.7 Function Definitions ____1.8 The Python “if” Statement ____1.9 The Python “while” Statement ____1.10 A Couple of Cool Little Apps ____1.11 Summary of Python Boolean Operators ____1.12 Function Arguments and Return Values ____1.13 The Forward Reference Problem ____1.14 Python Strings ____1.15 Python Lists (and a Cool Sorting App) ____1.16 The “for” Statement and Ranges ____1.17 Tuples ____1.18 Dictionaries ____1.19 Sets ____1.20 Global and Local Variables ____Summary ____Review Questions ____Suggested Problems Chapter 2 Advanced String Capabilities ____2.1 Strings Are Immutable ____2.2 Numeric Conversions, Including Binary ____2.3 String Operators (+, =, *, >, etc.) ____2.4 Indexing and Slicing ____2.5 Single-Character Functions (Character Codes) ____2.6 Building Strings Using “join” ____2.7 Important String Functions ____2.8 Binary, Hex, and Octal Conversion Functions ____2.9 Simple Boolean (“is”) Methods ____2.10 Case Conversion Methods ____2.11 Search-and-Replace Methods ____2.12 Breaking Up Input Using “split” ____2.13 Stripping ____2.14 Justification Methods ____Summary ____Review Questions ____Suggested Problems Chapter 3 Advanced List Capabilities ____3.1 Creating and Using Python Lists ____3.2 Copying Lists Versus Copying List Variables ____3.3 Indexing ________3.3.1 Positive Indexes ________3.3.2 Negative Indexes ________3.3.3 Generating Index Numbers Using “enumerate” ____3.4 Getting Data from Slices ____3.5 Assigning into Slices ____3.6 List Operators ____3.7 Shallow Versus Deep Copying ____3.8 List Functions ____3.9 List Methods: Modifying a List ____3.10 List Methods: Getting Information on Contents ____3.11 List Methods: Reorganizing ____3.12 Lists as Stacks: RPN Application ____3.13 The “reduce” Function ____3.14 Lambda Functions ____3.15 List Comprehension ____3.16 Dictionary and Set Comprehension ____3.17 Passing Arguments Through a List ____3.18 Multidimensional Lists ________3.18.1 Unbalanced Matrixes ________3.18.2 Creating Arbitrarily Large Matrixes ____Summary ____Review Questions ____Suggested Problems Chapter 4 Shortcuts, Command Line, and Packages ____4.1 Overview ____4.2 Twenty-Two Programming Shortcuts ________4.2.1 Use Python Line Continuation as Needed ________4.2.2 Use “for” Loops Intelligently ________4.2.3 Understand Combined Operator Assignment (+= etc.) ________4.2.4 Use Multiple Assignment ________4.2.5 Use Tuple Assignment ________4.2.6 Use Advanced Tuple Assignment ________4.2.7 Use List and String “Multiplication” ________4.2.8 Return Multiple Values ________4.2.9 Use Loops and the “else” Keyword ________4.2.10 Take Advantage of Boolean Values and “not” ________4.2.11 Treat Strings as Lists of Characters ________4.2.12 Eliminate Characters by Using “replace” ________4.2.13 Don’t Write Unnecessary Loops ________4.2.14 Use Chained Comparisons (n < x) and Get-Random-Number (!) ____14.11 RPN: Putting It All Together ____Summary ____Review Questions ____Suggested Problems Chapter 15 Getting Financial Data off the Internet ____15.1 Plan of This Chapter ____15.2 Introducing the Pandas Package ____15.3 “stock_load”: A Simple Data Reader ____15.4 Producing a Simple Stock Chart ____15.5 Adding a Title and Legend ____15.6 Writing a “makeplot” Function (Refactoring) ____15.7 Graphing Two Stocks Together ____15.8 Variations: Graphing Other Data ____15.9 Limiting the Time Period ____15.10 Split Charts: Subplot the Volume ____15.11 Adding a Moving-Average Line ____15.12 Giving Choices to the User ____Summary ____Review Questions ____Suggested Problems Appendix A: Python Operator Precedence Table Appendix B: Built-In Python Functions ____abs(x) ____all(iterable) ____any(iterable) ____ascii(obj) ____bin(n) ____bool(obj) ____bytes(source, encoding) ____callable(obj) ____chr(n) ____compile(cmd_str, filename, mode_str, flags=0, dont_inherit=False, optimize=–1) ____complex(real=0, imag=0) ____complex(complex_str) ____delattr(obj, name_str) ____dir([obj]) ____divmod(a, b) ____enumerate(iterable, start=0) ____eval(expr_str [, globals [,locals]] ) ____exec(object [, global [,locals]]) ____filter(function, iterable) ____float([x]) ____format(obj, [format_spec]) ____frozenset([iterable]) ____getattr(obj, name_str [,default]) ____globals() ____hasattr(obj, name_str) ____hash(obj) ____help([obj]) ____hex(n) ____id(obj) ____input([prompt_str]) ____int(x, base=10) ____int() ____isinstance(obj, class) ____issubclass(class1, class2) ____iter(obj) ____len(sequence) ____list([iterable]) ____locals() ____map(function, iterable1 [, iterable2…]) ____max(arg1 [, arg2]…) ____max(iterable) ____min(arg1 [, arg2]…) ____min(iterable) ____oct(n) ____open(file_name_str, mode='rt') ____ord(char_str) ____pow(x, y[, z]) ____print(objects, sep='', end='\n', file=sys.stdout) ____range(n) ____range(start, stop [, step]) ____repr(obj) ____reversed(iterable) ____round(x [,ndigits]) ____set([iterable]) ____setattr(obj, name_str, value) ____sorted(iterable [, key] [, reverse]) ____str(obj='') ____str(obj=b'' [, encoding='utf-8']) ____sum(iterable [, start]) ____super(type) ____tuple([iterable]) ____type(obj) ____zip(*iterables) Appendix C: Set Methods ____set_obj.add(obj) ____set_obj.clear() ____set_obj.copy() ____set_obj.difference(other_set) ____set_obj.difference_update(other_set) ____set_obj.discard(obj) ____set_obj.intersection(other_set) ____set_obj.intersection_update(other_set) ____set_obj.isdisjoint(other_set) ____set_obj.issubset(other_set) ____set_obj.issuperset(other_set) ____set_obj.pop() ____set_obj.remove(obj) ____set_obj.symmetric_difference(other_set) ____set_obj.symmetric_difference_update(other_set) ____set_obj.union(other_set) ____set_obj.union_update(other_set) Appendix D: Dictionary Methods ____dict_obj.clear() ____dict_obj.copy() ____dict_obj.get(key_obj, default_val = None) ____dict_obj.items() ____dict_obj.keys() ____dict_obj.pop(key [, default_value]) ____dict_obj.popitem() ____dict_obj.setdefault(key, default_value=None) ____dict_obj.values() ____dict_obj.update(sequence) Appendix E: Statement Reference ____Variables and Assignments ____Spacing Issues in Python ____Alphabetical Statement Reference ________assert Statement ________break Statement ________class Statement ________continue Statement ________def Statement ________del Statement ________elif Clause ________else Clause ________except Clause ________for Statement ________global Statement ________if Statement ________import Statement ________nonlocal Statement ________pass Statement ________raise Statement ________return Statement ________try Statement ________while Statement ________with Statement ________yield Statement Index
Similar books
Supercharged Python: Take Your Code to the Next Level
2019 · EPUB
Supercharged Python: Take Your Code to the Next Level
2019 · PDF
Supercharged Python: Take Your Code to the Next Level
2019 · PDF
MySQL® Notes for Professionals book
2018 · PDF
MrExcel 2022: Boosting Excel
2022 · PDF
MrExcel 2022: Boosting Excel
2022 · PDF
Session C11: Ancient Cultural Landscapes in South Europe – their Ecological Setting and Evolution, Session C22: Gardeners from South America, Session S04: Agro-Pastoralism and Early Metallurgy Sessions, Session WS29: The Idea of Enclosure in Recent Iberian Prehistory, Session C88: Rhytmes et causalites des dynamiques de l'anthropisation en Europe entre 6500 ET 500 BC: Hypotheses socio-culturelles et/ou climatiques: Proceedings of the XV UISPP World Congress (Lisbon 4-9 September 2006) / Actes du XV Congrès Mondial (Lisbonne 4-9 Septembre 2006) Vol.36
2010 · PDF
THE BRITISH ARMY IN INDIA: ITS PRESERVATION BY AN APPROPRIATE CLOTHING, HOUSING, LOCATING, RECREATIVE EMPLOYMENT, AND HOPEFUL ENCOURAGEMENT OF THE TROOPS. with AN APPENDIX ON INDIA : THE CLIMATE OP ITS HILLS ; THE DEVELOPMENT OF ITS RESODRCBS, INDUSTRY, AND ARTS ; THE ADMINISTRATION OF JUSTICE ; THE BLACK ACT ; THE PROGRESS OF CHRISTIANITY ; THE TRAFFIC IN OPIUM ; THE VALUE OF INDIA ; PERMANENT CAUSES OF DISAFFECTION, AND OF THE RECENT REBELLION ; THE TRADITIONARY POLICY; MISGOVERNMENT BY NATIVE RULERS ; ANNEXATIONS OF THEIR TERRITORY, ETC.
1858 · PDF