Unformatted text preview:

Modern Python Cookbook The latest in modern Python recipes for the busy modern programmer Steven F Lott BIRMINGHAM MUMBAI Modern Python Cookbook Copyright 2016 Packt Publishing All rights reserved No part of this book may be reproduced stored in a retrieval system or transmitted in any form or by any means without the prior written permission of the publisher except in the case of brief quotations embedded in critical articles or reviews Every effort has been made in the preparation of this book to ensure the accuracy of the information presented However the information contained in this book is sold without warranty either express or implied Neither the author nor Packt Publishing and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals However Packt Publishing cannot guarantee the accuracy of this information First published November 2016 Production reference 1211116 Published by Packt Publishing Ltd Livery Place 35 Livery Street Birmingham B3 2PB UK ISBN 978 1 78646 925 0 www packtpub com Credits Author Steven F Lott Reviewers Sanjeev Kumar Jaiswal Dr Vahid Mirjalili Copy Editor Safis Editing Project Coordinator Suzanne Coutinho Commissioning Editor Kunal Parikh Proofreader Safis Editing Acquisition Editor Sonali Vernekar Indexer Tejal Daruwale Soni Content Development Editor Zeeyan Pinheiro Graphics Kirk D Penha Technical Editors Pratish Shetty Abhishek Sharma Production Coordinator Aparna Bhagat About the Author Steven F Lott has been programming since the 70s when computers were large expensive and rare As a contract software developer and architect he has worked on hundreds of projects from very small to very large He s been using Python to solve business problems for over 10 years He s currently leveraging Python to implement microservices and ETL pipelines His other titles with Packt Publishing include Python Essentials Mastering Object Oriented Python Functional Python Programming and Python for Secret Agents Steven is currently a technomad who lives in various places on the east coast of the U S His technology blog is h t t p s l o t t s o f t w a r e a r c h i t e c t b l o g s p o t c o m and his LinkedIn address is h t t p s w w w l i n k e d i n c o m i n s t e v e n l o t t 029835 About the Reviewers Sanjeev Jaiswal is a computer graduate with 7 years of industrial experience in web development and cyber security He basically uses Perl Python and GNU Linux for his day to day activities He is currently working on projects involving penetration testing source code review and security design and implementations He is very much interested in web and cloud security You can follow him on Twitter at aliencoders and on GitHub at h t t p s g i t h u b c o m j a s s i c s He has written Instant PageSpeed Optimization and co authored Learning Django Web Development for Packt Publishing He has reviewed more than 5 books for Packt Publishing and looks forward to authoring or reviewing more books for Packt Publishing and other publishers Vahid Mirjalili is a software engineer and data scientist currently working towards his PhD study in Computer Science at Michigan State University His research at the i PRoBE integrated pattern recognition and biometrics lab involves attribute classification of face images from large image datasets Furthermore he teaches Python programming as well as computing concepts for data analysis and databases Owing to his specialty in data mining he is very interested in predictive modeling and getting insights from data He is also a Python developer and likes to contribute to the open source community Moreover he enjoys making tutorials for different directions of data science and computer algorithms which can be found in his GitHub repository at h t t p g i t h u b c o m m i r j a l i l D a t a S c i e n c e www PacktPub com For support files and downloads related to your book please visit www PacktPub com Did you know that Packt offers eBook versions of every book published with PDF and ePub files available You can upgrade to the eBook version at www PacktPub com and as a print book customer you are entitled to a discount on the eBook copy Get in touch with us at service packtpub com for more details At www PacktPub com you can also read a collection of free technical articles sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks h t t p s w w w p a c k t p u b c o m m a p t Get the most in demand software skills with Mapt Mapt gives you full access to all Packt books and video courses as well as industry leading tools to help you plan your personal development and advance your career Why subscribe Fully searchable across every book published by Packt Copy and paste print and bookmark content On demand and accessible via a web browser Table of Contents Preface Chapter 1 Numbers Strings and Tuples Introduction Creating meaningful names and using variables Choosing names wisely Assigning names to objects Working with large and small integers Getting ready How to do it How it works There s more See also Getting ready How to do it How it works There s more See also Getting ready How to do it How it works There s more See also Getting ready How to do it Choosing between float decimal and fraction Doing currency calculations Fraction calculations Floating point approximations Converting numbers from one type to another Choosing between true division and floor division Doing floor division Doing true division Rational fraction calculations How it works See also Rewriting an immutable string 1 6 6 7 7 8 8 10 11 12 12 13 13 13 14 16 17 17 17 18 18 19 20 21 22 23 24 25 25 25 26 26 27 27 28 28 Getting ready How to do it Slicing a piece of a string Updating a string with a replacement Making a string all lowercase Removing extra punctuation marks String parsing with regular expressions Building complex strings with template format Building complex strings from lists of characters How it works There s more See also Getting ready How to do it How it works There s more See also Getting ready How to do it How it works There s more See also Getting ready How to do it How it works There s more See also Getting ready How to do it How it works See also Getting ready How to do


View Full Document

Python

Download Python
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Python and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Python 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?