1. Trang chủ
  2. » Công Nghệ Thông Tin

Python crash course a hands on, project based introduction to programming

562 5,1K 1

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 562
Dung lượng 5,55 MB

Nội dung

Lập trình Python từ cơ bản đến nâng cao có các bài tập đi kèm để luyện kỹ năng.Là cuốn sách lập trình được recommend trên các trang về lập trình lớn hiện nayPython crash course a hands on, project based introduction to programming Python crash course a hands on, project based introduction to programming Python crash course a hands on, project based introduction to programming Python crash course a hands on, project based introduction to programming

PY THON LEARN PYTHON— FAST! In the first half of the book, you’ll learn about basic programming concepts, such as lists, dictionaries, classes, and loops, and practice writing clean and readable code with exercises for each topic You’ll also learn how to make your programs interactive and how to test your code safely before adding it to a project In the second half of the book, you’ll put your new knowledge into practice with three substantial projects: a Space Invaders–inspired arcade game, data visualizations with Python’s super-handy libraries, and a simple web app you can deploy online As you work through Python Crash Course, you’ll learn how to: • Use powerful Python libraries and tools, including matplotlib, NumPy, and Pygal • Make 2D games that respond to keypresses and mouse clicks, and that grow more difficult as the game progresses • Work with data to generate interactive visualizations • Create and customize simple web apps and deploy them safely online • Deal with mistakes and errors so you can solve your own programming problems If you’ve been thinking seriously about digging into programming, Python Crash Course will get you up to speed and have you writing real programs fast Why wait any longer? Start your engines and code! 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 COVERS PYTHON AND PY THON CR A SH COURSE Python Crash Course is a fast-paced, thorough introduction to programming with Python that will have you writing programs, solving problems, and making things that work in no time T H E F I N E ST I N G E E K E N T E RTA I N M E N T ™ “ I L I E F L AT ” $39.95 ($45.95 CDN) SHELVE IN: PROGRAMMING LANGUAGES/ PYTHON This book uses RepKover — a durable binding that won’t snap shut MATTHES w w w.nostarch.com CR ASH COURSE A H A N D S - O N , P R O J E C T - B A S E D I N T R O D U C T I O N T O P R O G R A M M I N G ERIC MAT THES Python Crash Course Python Crash Course A Hands-On, Project-Based Introduction to Programming b y E r ic M a t t h e s San Francisco Python Crash Course Copyright © 2016 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 First printing 19 18 17 16 15   ISBN-10: 1-59327-603-6 ISBN-13: 978-1-59327-603-4 Publisher: William Pollock Production Editor: Riley Hoffman Cover Illustration: Josh Ellingson Interior Design: Octopod Studios Developmental Editors: William Pollock, Liz Chadwick, and Leslie Shen Technical Reviewer: Kenneth Love Copyeditor: Anne Marie Walker Compositor: Riley Hoffman 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: 415.863.9900; info@nostarch.com www.nostarch.com Library of Congress Cataloging-in-Publication Data Matthes, Eric, 1972Python 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 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 and teacher for many years He has given talks and tutorials at conferences, done professional trainings, been a Python and Django freelancer, and now teaches for an online education company Kenneth is also the co-creator of the django-braces package, which provides several handy mixins for Django’s 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 Acknowledgments xxvii Introduction xxix Part I: Basics Chapter 1: Getting Started Chapter 2: Variables and Simple Data Types 19 Chapter 3: Introducing Lists 37 Chapter 4: Working with Lists 53 Chapter 5: if Statements 75 Chapter 6: Dictionaries 95 Chapter 7: User Input and while Loops 117 Chapter 8: Functions 133 Chapter 9: Classes 161 Chapter 10: Files and Exceptions 189 Chapter 11: Testing Your Code 215 Part II: Projects 231 Project 1: Alien Invasion Chapter 12: A Ship That Fires Bullets 235 Chapter 13: Aliens! 265 Chapter 14: Scoring 291 Index Symbols + (addition), 30 * (asterisk) operator, 157 bmp (Bitmap) image files, 244 + (concatenation operator), 101–102 / (division), 30 == (equality operator), 77 > (greater than), 79 >= (greater than or equal to), 79 # (hash mark), for comments, 33 != (inequality operator), 78 < (less than), 79 ), 79 greater than or equal to (>=), 79 greeter.py, 118–119, 134–135 greet_users.py, 147 gunicorn, 469, 470–471 H Hacker News, 390 hash mark (#), for comments, 33 head, of an HTML file, 458 HEAD (Git), 512 Hello World, hello_world.py, 19–23 Heroku See also Django; Learning Log project Bash, 475 databases migrating, 474 setting up, 474 using Postgres, 469 Index   519 Heroku, continued making an account, 466 Procfile, 469 projects deleting, 481 pushing to, 473 securing, 476 Python runtime, specifying, 468 settings.py, modifying for, 468 superuser, creating, 475 Toolbelt, installing, 466 user-friendly URLs, 476 wsgi.py, modifying for, 470 hex format, for colors, 373 highs_lows.py, 350–361 hn_submissions.py, 391–393 Homebrew, 487 I IDLE, 496–497 commenting out code, 497 customizing settings, 497 installing on Linux, 496 on OS X, 496 on Windows, 497 if statements and keyword, 79–80 Boolean expressions, 81 checking for empty lists, 91 equality (==), 76–78 inequality (!=), 78 items in a list, 80–81 items not in a list, 81 special items, 90–91 elif statement, 84–88 else statement, 83–84 if-elif-else chains, 84–93 lists and, 89–92 numerical comparisons, 78–80 or keyword, 80 simple, 82–83 styling guidelines, 94 testing multiple conditions, 87–88 import *, 157 import this, 34 520   Index indentation errors, 57–60 index errors, 51 inequality operator (!=), 78 infinite loops, 126–127 inheritance, 172 See also classes: inheritance input() function numerical input, 119–120 prompts, 118–119 insert() method, 42 int, 31 IRC (Internet relay chat), 502–503 itemgetter() function, 391–392 items() method, 103 J jQuery, 457 json.dump() function, 209 JSON files converting strings to numerical values, 364 extracting data, 363 json.load() function, 210 jumbotron, 461 K keys() method, 104 key-value pairs, 96 See also dictionaries keyword arguments, 136, 137–138 keywords, 489 L language_survey.py, 224 Learning Log project, 397 See also Django; Heroku deployment commits, using Git, 471–473 custom error pages, 478–480 get_object_or_404() method, 480 ignoring files in Git, 472 making a static file directory, 470 ongoing development, 480 Procfile, 469 requirements.txt, 467 SECRET_KEY setting, 481 using gunicorn locally, 470 HTML headers, defining, 458 logging out, 442–443 login page, 440–442 migrating the database, 450–451 styling, 456 Bootstrap, 457 collapsible navigation, 459 jumbotron, 461 navigation bar, 458–460 selectors, 459 registration page, 443–446 users app default login view, 440 displaying messages to logged-in users, 441 logging in a user, 445 UserCreationForm, 445 len() function, 49 less than (

Ngày đăng: 18/05/2017, 08:45

TỪ KHÓA LIÊN QUAN