Learn Python Programming
Second Edition
A beginner's guide to learning the fundamentals of Python language to write efficient, high-quality code
Fabrizio Romano
BIRMINGHAM - MUMBAI
Learn Python ProgrammingSecond Edition
Copyright 2018 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(s), nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been 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.
Commissioning Editor: Richa Tripathi
Acquisition Editor: Karan Sadawana
Content Development Editor: Rohit Singh
Technical Editor: Romy Dias
Copy Editor: Safis Editing
Project Coordinator: Vaidehi Sawant
Proofreader: Safis Editing
Indexer: Mariammal Chettiyar
Graphics: Jason Monteiro
Production Coordinator: Shantanu Zagade
First published: December 2015
Second edition: June 2018
Production reference: 1280618
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78899-666-2
www.packtpub.com
To my dear dear friend and mentor, Torsten Alexander Lange.
Thank you for all the love and support.
mapt.io
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
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.
Foreword
I first got to know Fabrizio when he became our lead developer a few years ago. It was quickly apparent that he was one of those rare people who combine rigorous technical expertise with a genuine care for the people around him and a true passion to mentor and teach. Whether it was designing a system, pairing to write code, doing code reviews, or even organizing team card games at lunch, Fab was always thinking not only about the best way to do the job, but also about how to make sure that the entire team had the skills and motivation to do their best.
You'll meet the same wise and caring guide in this book. Every chapter, every example, every explanation has been carefully thought out, driven by a desire to impart the best and most accurate understanding of the technology, and to do it with kindness. Fab takes you under his wing to teach you both Python's syntax and its best practices.
I'm also impressed with the scope of this book. Python has grown and evolved over the years, and it now spans an enormous ecosystem, being used for web development, routine data handling, and ETL, and increasingly for data science. If you are new to the Python ecosystem, it's often hard to know what to study to achieve your goals. In this book, you will find useful examples exposing you to many different uses of Python, which will help guide you as you move through the breadth that Python offers.
I hope you will enjoy learning Python and become a member of our global community. I'm proud to have been asked to write this, but above all, I'm pleased that Fab will be your guide.
Naomi Ceder
Python Software Foundation Fellow
Contributors
About the author
Fabrizio Romano was born in Italy in 1975. He holds a master's degree in computer science engineering from the University of Padova. He is also a certified scrum master, Reiki master and teacher, and a member of CNHC.
He moved to London in 2011 to work for companies such as Glasses Direct, TBG/Sprinklr, and student.com. He now works at Sohonet as a Principal Engineer/Team Lead.
He has given talks on Teaching Python and TDD at two editions of EuroPython, and at Skillsmatter and ProgSCon, in London.
I'm grateful to all those who helped me create this book. Special thanks to Dr. Naomi Ceder for writing the foreword to this edition, and to Heinrich Kruger and Julio Trigo for reviewing this volume. To my friends and family, who love me and support me every day, thank you. And to Petra Lange, for always being so lovely to me, thank you.
About the reviewers
Heinrich Kruger was born in South Africa in 1981. He obtained a bachelor's degree with honors from the University of the Witwatersrand in South Africa in 2005 and a master's degree in computer science from Utrecht University in the Netherlands in 2008.
He worked as a research assistant at Utrecht University from 2009 until 2013 and has been working as a professional software developer developer since 2014. He has been using Python for personal and projects and in his studies since 2004, and professionally since 2014.
Julio Vicente Trigo Guijarro is a computer scientist and software engineer with over a decade of experience in software development. He completed his studies at the University of Alicante, Spain, in 2007. He has worked with several technologies and languages, including Microsoft Dynamics NAV, Java, JavaScript, and Python. He is a certified Scrum Master. He has been using Python since 2012, and he is passionate about software design, quality, and coding standards. He currently works as senior software developer and team lead at Sohonet, developing real-time collaboration applications.
I would like to thank my parents for their love, good advice, and continuous support. I would also like to thank all the friends I have met along the way, who enriched my life, for keeping up my motivation, and make me progress.
Packt is searching for authors like you
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.