PRAISE FOR PYTHON CRASH COURSE
It has been interesting to see No Starch Press producing future classics that should be alongside the more traditional programming books. Python Crash Course is one of those books.
GREG LADEN, SCIENCEBLOGS
Deals with some rather complex projects and lays them out in a consistent, logical, and pleasant manner that draws the reader into the subject.
FULL CIRCLE MAGAZINE
Well presented with good explanations of the code snippets. The book works with you, one small step at a time, building more complex code, explaining whats going on all the way.
FLICKTHROUGH REVIEWS
Learning Python with Python Crash Course was an extremely positive experience! A great choice if youre new to Python.
MIKKE GOES CODING
Does what it says on the tin, and does it really well.... Presents a large number of useful exercises as well as three challenging and entertaining projects.
REALPYTHON.COM
A fast-paced but comprehensive introduction to programming with Python, Python Crash Course is another superb book to add to your library and help you finally master Python.
TUTORIALEDGE.NET
A brilliant option for complete beginners without any coding experience. If youre looking for a solid, uncomplicated intro to this very deep language, I have to recommend this book.
WHATPIXEL.COM
Contains literally everything you need to know about Python and even more.
FIREBEARSTUDIO.COM
PYTHON CRASH COURSE
2ND EDITION
A Hands-On, Project-Based Introduction to Programming
by Eric Matthes
San Francisco
PYTHON CRASH COURSE, 2ND EDITION. Copyright 2019 by Eric Matthes.
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher.
ISBN-10: 1-59327-928-0
ISBN-13: 978-1-59327-928-8
Publisher: William Pollock
Production Editor: Riley Hoffman
Cover Illustration: Josh Ellingson
Cover and Interior Design: Octopod Studios
Developmental Editor: Liz Chadwick
Technical Reviewer: Kenneth Love
Copyeditor: Anne Marie Walker
Compositors: Riley Hoffman and Happenstance Type-O-Rama
Proofreader: James Fraleigh
For information on distribution, translations, or bulk sales, please contact No Starch Press, Inc. directly:
No Starch Press, Inc.
245 8th Street, San Francisco, CA 94103
phone: 1.415.863.9900;
www.nostarch.com
The Library of Congress has catalogued the first edition as follows:
Matthes, Eric, 1972
Python crash course : a hands-on, project-based introduction to programming / by Eric Matthes.
pages cm
Includes index.
Summary: "A project-based introduction to programming in Python, with exercises. Covers general
programming concepts, Python fundamentals, and problem solving. Includes three projects - how to
create a simple video game, use data visualization techniques to make graphs and charts, and build
an interactive web application"-- Provided by publisher.
ISBN 978-1-59327-603-4 -- ISBN 1-59327-603-6
1. Python (Computer program language) I. Title.
QA76.73.P98M38 2015
005.13'3--dc23
2015018135
No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other product and company names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
The information in this book is distributed on an As Is basis, without warranty. While every precaution has been taken in the preparation of this work, neither the author nor No Starch Press, Inc. shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it.
About the Author
Eric Matthes is a high school science and math teacher living in Alaska, where he teaches an introductory Python course. He has been writing programs since he was five years old. Eric currently focuses on writing software that addresses inefficiencies in education and brings the benefits of open source software to the field of education. In his spare time he enjoys climbing mountains and spending time with his family.
About the Technical Reviewer
Kenneth Love has been a Python programmer, teacher, and conference organizer for many years. He has spoken and taught at many conferences, been a Python and Django freelancer, and is currently a software engineer for OReilly Media. Kenneth is co-creator of the django-braces package, which provides several handy mixins for Djangos class-based views. You can keep up with him on Twitter at @kennethlove.
For my father, who always made time to answer my questions about programming, and for Ever, who is just beginning to ask me his questions
BRIEF CONTENTS
PREFACE TO THE SECOND EDITION
The response to the first edition of Python Crash Course has been overwhelmingly positive. More than 500,000 copies are in print, including translations in eight languages. Ive received letters and emails from readers as young as 10, as well as from retirees who want to learn to program in their free time. Python Crash Course is being used in middle schools and high schools, and also in college classes. Students who are assigned more advanced textbooks are using Python Crash Course as a companion text for their classes and finding it a worthwhile supplement. People are using it to enhance their skills on the job and to start working on their own side projects. In short, people are using the book for the full range of purposes I had hoped they would.
The opportunity to write a second edition of Python Crash Course has been thoroughly enjoyable. Although Python is a mature language, it continues to evolve as every language does. My goal in revising the book was to make it leaner and simpler. There is no longer any reason to learn Python 2, so this edition focuses on Python 3 only. Many Python packages have become easier to install, so setup and installation instructions are easier. Ive added a few topics that Ive realized readers would benefit from, and Ive updated some sections to reflect new, simpler ways of doing things in Python. Ive also clarified some sections where certain details of the language were not presented as accurately as they could have been. All the projects have been completely updated using popular, well-maintained libraries that you can confidently use to build your own projects.
The following is a summary of specific changes that have been made in the second edition:
- In , the instructions for installing Python have been simplified for users of all major operating systems. I now recommend the text editor Sublime Text, which is popular among beginner and professional programmers and works well on all operating systems.
- for the benefit of all readers. Finally, a clear convention for representing constant values in Python is included in this chapter.