La lecture à portée de main
Vous pourrez modifier la taille du texte de cet ouvrage
Découvre YouScribe en t'inscrivant gratuitement
Je m'inscrisDécouvre YouScribe en t'inscrivant gratuitement
Je m'inscrisVous pourrez modifier la taille du texte de cet ouvrage
Description
Sujets
Informations
Publié par | BPB Publications |
Date de parution | 19 décembre 2019 |
Nombre de lectures | 10 |
EAN13 | 9789389423730 |
Langue | English |
Informations légales : prix de location à la page 0,0600€. Cette information est donnée uniquement à titre indicatif conformément à la législation en vigueur.
Extrait
Python for Professionals
Learning Python as a Second Language
by
Matt Telles
FIRST EDITION 2020
Copyright © BPB Publications, India
ISBN: 978-93-89423-754
All Rights Reserved. No part of this publication may be reproduced or distributed in any form or by any means or stored in a database or retrieval system, without the prior written permission of the publisher with the exception to the program listings which may be entered, stored and executed in a computer system, but they can not be reproduced by the means of publication.
LIMITS OF LIABILITY AND DISCLAIMER OF WARRANTY
The information contained in this book is true to correct and the best of author’s & publisher’s knowledge. The author has made every effort to ensure the accuracy of these publications, but cannot be held responsible for any loss or damage arising from any information in this book.
All trademarks referred to in the book are acknowledged as properties of their respective owners.
Distributors:
BPB PUBLICATIONS
20, Ansari Road, Darya Ganj
New Delhi-110002
Ph: 23254990/23254991
MICRO MEDIA
Shop No. 5, Mahendra Chambers,
150 DN Rd. Next to Capital Cinema,
V.T. (C.S.T.) Station, MUMBAI-400 001
Ph: 22078296/22078297
DECCAN AGENCIES
4-3-329, Bank Street,
Hyderabad-500195
Ph: 24756967/24756400
BPB BOOK CENTRE
376 Old Lajpat Rai Market,
Delhi-110006
Ph: 23861747
Published by Manish Jain for BPB Publications, 20 Ansari Road, Darya Ganj, New Delhi-110002 and Printed by him at Repro India Ltd, Mumbai
Dedicated to
My wife Teresa
About the Author
Matt Telles is a 35-year veteran in the software industry. He has worked with virtually all programming languages, and has been a developer, manager, tester, and designer. He’s been working on Python for several years and is constantly extending his knowledge in the field.
Matt is married with three children, living in New York, the United States. He has a menagerie of cats, dogs and a turtle, and loves reading books on his Microsoft Surface on the train to work every morning.
About the Reviewer
Tarun Behal is a computer scientist and software engineer with almost 8 years of experience in software development. He completed his graduation in computer science and software engineering from UPTU, India, in 2012. Currently pursuing masters from BITS Pilani, India. Since then, he has worked with several technologies and languages, including Odoo, Django, JavaScript, Ruby, PHP and Python. He currently resides in Noida, India and works for Adobe Inc.
Some of the applications covered by Tarun during his career include RESTful APIs, ERPs, billing platforms, hotel management, financial systems and e-commerce websites. He has been using Python on both personal and professional projects since 2012, and he is passionate about software design, software quality, and coding standards.
I would like to thank my parents for their love, good advice, and continuous support. I would also like to thank all my friends that I met along the way, who enriched my life, for motivating me and helping me progress.
Acknowledgement
First and foremost, I would like to thank all of the employers who have allowed me to learn my skills while working for them. Thank you for that opportunity.
Secondly, I would like to thank my family, who have put up with me while writing this book.
Finally, I’d like to thank everyone who reads the book, and finds anything in it to be useful in their daily lives. I’ve spend a lot of time over the years learning from others, this is my chance to give back to the community.
– Matt Telles
Preface
Python has become very popular among programmers, testers, and web developers. The majority of Python is easy to pick up and run with right away, but the details of the language are sometimes a bit difficult to understand without good examples. The purpose of this book is to help a professional programmer get started quickly with the language. The target audience of this book is someone who has written programs in the past, not necessarily in Python though. This book is divided into 10 chapters and it provides a detailed description of the core concepts of Python programming.
Chapter 1 introduces the history and installation of Python, as well as the differences between the current versions to help you determine which one to install.
Chapter 2 addresses the basic data types in Python, as well as the collections and iterables.
Chapter 3 discusses the nuts and bolts of Pythons, with a focus on conditional statements, loops, and objects, with their attributes.
Chapter 4 discusses how to work with Python, from the immediate mode of the interpreter to the importing of pre-built packages and modules for use in your application.
Chapter 5 is involved with object-oriented programming as it applies to Python. You will learn about the pillars of object orientation and how they are implemented using the Python programming language.
Chapter 6 addresses the concepts of advanced manipulations in Python. You will learn about comprehensions, generators and slices.
Chapter 7 is all about input and output in Python, from writing to the console to reading and writing files. You’ll learn about JSON and text files, as well as working with binary file formats.
Chapter 8 describes imports and exports, how to use other people’s code and make your own code available for the community or your own company.
Chapter 9 addresses a variety of miscellaneous topics, from decorators and properties to documentation and metaclasses.
Chapter 10 will help you to focus on not reinventing the wheel by exploring some of the more popular Python packages available to you, and looking at how to use them in your own programs.
Chapter 11 will present a series of tips and tricks that you can use to immediately upgrade your Python programming skills.
Errata
We take immense pride in our work at BPB Publications and follow best practices to ensure the accuracy of our content to provide with an indulging reading experience to our subscribers. Our readers are our mirrors, and we use their inputs to reflect and improve upon human errors if any, occurred during the publishing processes involved. To let us maintain the quality and help us reach out to any readers who might be having difficulties due to any unforeseen errors, please write to us at :
errata@bpbonline.com
Your support, suggestions and feedbacks are highly appreciated by the BPB Publications’ Family.
Table of Contents
1. The History and Installation of Python
Introduction
Structure
Objectives
Python: the language
History
Selecting a Python version
Why not use 2.7?
Which 3.x to use?
Installing
Testing your installation
The Zen of Python
Keeping it simple
Keeping it readable
Never is better than right now
Using pip
Using virtual environments
Python IDE’s and command line work
Hello world
Conclusion
Questions
2. Python Types and Constructs
Introduction
Structure
Objectives
Integers
Floating point numbers
Boolean
Complex values
Variable naming
Strings
Finding substrings
Multiple line strings
Concatenating
Other methods
Python Collections
Lists
Dictionaries
Getting the value of a key
Testing if a key is in a dictionary
Iterating
Length of a dictionary
Adding new items
Nested dictionaries
Sets
Tuples
Iterators and iterables
Sorted
The zip function
Booleans and truthiness
Comments
Conclusion
Questions
3. The Nuts and Bolts
Introduction
Structure
Objectives
Conditionals
The “walrus” operator
ANDs, ORs, NOTs, and logicals
Indentation
The pass statement
Loops
Functions
Parameters
Return values
Required vs optional arguments
Keyword arguments
Variable length arguments
Lambdas
Classes
Scoping
Objects
Conclusion
Questions
4. Organizational Skills
Introduction
Structure
Objectives
Immediate mode
Modules
Packages
Importing
Paths
Dot notation in naming
Installing packages using pip
Insuring requirements with pip
User installs vs system installs
Conclusion
Questions
5. Object-Oriented Programming
Introduction
Structure
Objective
Object-oriented programming with Python
Abstraction
Encapsulation
Inheritance
Multiple inheritance
Polymorphism, the Python way
Overloading of methods
Overloading of operators
Comparisons and overloading
Read-only attributes
The __new__operator
Classes and Iteratables
Chaining of operations
Initialization
Conclusion
Questions
6. Advanced Manipulations
Introduction
Structure
Objectives
List comprehensions
Dictionary comprehensions
Nested dictionary comprehensions
Applying functions
Restrictions on dictionary comprehensions
Set comprehensions
Generators
Building a string from a list
Searching a string
Searching a collection
Using a set of functions to create an extensible state machine
Filtering vs removing
Slicing
Lambda expressions
The ‘splat’ operator and unpacking
Conclusion
Questions
7. File Input and Output
Introduction
Structure
Objectives
Files
Working with files
Using the with statement
Reading fixed length data from files in Python
Reading a text file by lines in Python
A readlines real-world example
Python and binary files
JSON parsing
JSON writing
Serializing complex objects in JSON
Reading in text vs reading in lines
Writing out lines
Output formatting
Pickling
Conclusion
Questions
8. Imports and Reuse
Introduction
Structure
Objectives
Import and reuse of code
Importing
Importing modules
Importing packages
Dynamic imports
Working with the os module
Directory and file information
Listing installed packages
Reflection
Using Reflection
Conclusion
Questions
9. Miscellaneous
Introduction
Structure
Objectives
Decorators
Variable arguments
Character encoding
Properties
Description st