ebook img

Beginning Programming with Python For Dummies PDF

411 Pages·2014·10.78 MB·English
by  
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Beginning Programming with Python For Dummies

www.it-ebooks.info www.it-ebooks.info Beginning Programming with Python ® www.it-ebooks.info www.it-ebooks.info Beginning Programming with Python ® by John Paul Mueller www.it-ebooks.info Beginning Programming with Python® For Dummies® Published by: John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030-5774, www.wiley.com Copyright © 2014 by John Wiley & Sons, Inc., Hoboken, New Jersey Media and software compilation copyright © 2014 by John Wiley & Sons, Inc. All rights reserved. Published simultaneously in Canada No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permit- ted under Sections 107 or 108 of the 1976 United States Copyright Act, without the prior written permis- sion of the Publisher. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions. Trademarks: Wiley, For Dummies, the Dummies Man logo, Dummies.com, Making Everything Easier, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and may not be used without written permission. Python is a registered trademark of Python Software Foundation Corporation. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc. is not associated with any product or vendor mentioned in this book. LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITH- OUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ. For general information on our other products and services, please contact our Customer Care Department within the U.S. at 877-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002. For technical support, please visit www.wiley.com/techsupport. Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with standard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at http://booksupport.wiley.com. For more information about Wiley products, visit www.wiley.com. Library of Congress Control Number: 2014935516 ISBN 978-1-118-89145-2 (pbk); ISBN 978-1-118-89147-6 (ebk); ISBN ePDF 978-1-118-89149-0 (ebk) Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 www.it-ebooks.info Contents at a Glance Introduction ................................................................ 1 Part I: Getting Started with Python ............................... 5 Chapter 1: Talking to Your Computer .............................................................................7 Chapter 2: Getting Your Own Copy of Python .............................................................21 Chapter 3: Interacting with Python ...............................................................................39 Chapter 4: Writing Your First Application ....................................................................57 Part II: Talking the Talk ............................................. 81 Chapter 5: Storing and Modifying Information ............................................................83 Chapter 6: Managing Information ..................................................................................93 Chapter 7: Making Decisions ........................................................................................117 Chapter 8: Performing Repetitive Tasks .....................................................................133 Chapter 9: Dealing with Errors .....................................................................................149 Part III: Performing Common Tasks ........................... 181 Chapter 10: Interacting with Modules .........................................................................183 Chapter 11: Working with Strings ................................................................................205 Chapter 12: Managing Lists ..........................................................................................223 Chapter 13: Collecting All Sorts of Data ......................................................................243 Chapter 14: Creating and Using Classes .....................................................................267 Part IV: Performing Advanced Tasks ......................... 291 Chapter 15: Storing Data in Files ..................................................................................293 Chapter 16: Sending an E-Mail ......................................................................................309 Part V: The Part of Tens ........................................... 327 Chapter 17: Ten Amazing Programming Resources ..................................................329 Chapter 18: Ten Ways to Make a Living with Py thon ...............................................339 Chapter 19: Ten Interesting Tools ...............................................................................347 Chapter 20: Ten Libraries You Need to Know About ................................................357 Index ...................................................................... 365 www.it-ebooks.info www.it-ebooks.info Table of Contents Introduction ................................................................. 1 About This Book ..............................................................................................1 Foolish Assumptions .......................................................................................2 Icons Used in This Book .................................................................................3 Beyond the Book .............................................................................................3 Where to Go from Here ...................................................................................4 Part I: Getting Started with Python ............................... 5 Chapter 1: Talking to Your Computer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Understanding Why You Want to Talk to Your Computer .........................7 Knowing that an Application is a Form of Communication .......................9 Thinking about procedures you use daily ..........................................9 Writing procedures down ...................................................................10 Seeing applications as being like any other procedure ..................11 Understanding that computers take things literally .......................11 Defining What an Application Is ..................................................................12 Understanding that computers use a special language ..................12 Helping humans speak to the computer ...........................................13 Understanding Why Python is So Cool .......................................................14 Unearthing the reasons for using Python .........................................15 Deciding how you can personally benefit from Python ..................16 Discovering which organizations use Python ..................................17 Finding useful Python applications ...................................................18 Comparing Python to other languages .............................................18 Chapter 2: Getting Your Own Copy of Python . . . . . . . . . . . . . . . . . . . . . 21 Downloading the Version You Need ...........................................................21 Installing Python ............................................................................................24 Working with Windows .......................................................................25 Working with the Mac .........................................................................27 Working with Linux ..............................................................................29 Accessing Python on Your Machine ...........................................................32 Using Windows .....................................................................................32 Using the Mac .......................................................................................35 Using Linux ...........................................................................................36 Testing Your Installation ..............................................................................36 www.it-ebooks.info viii Beginning Programming with Python For Dummies Chapter 3: Interacting with Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Opening the Command Line .........................................................................40 Starting Python ....................................................................................41 Using the command line to your advantage .....................................42 Using Python environment variables to your advantage ...............44 Typing a Command .......................................................................................45 Telling the computer what to do .......................................................46 Telling the computer you’re done .....................................................46 Seeing the result...................................................................................46 Using Help .......................................................................................................48 Getting into help mode........................................................................48 Asking for help .....................................................................................49 Leaving help mode ...............................................................................52 Obtaining help directly .......................................................................52 Closing the Command Line ..........................................................................54 Chapter 4: Writing Your First Application . . . . . . . . . . . . . . . . . . . . . . . . 57 Understanding the Integrated DeveLopment Environment (IDLE) .........58 Starting IDLE ...................................................................................................59 Using standard commands .................................................................60 Understanding color coding ...............................................................61 Getting GUI help ...................................................................................62 Configuring IDLE ..................................................................................63 Creating the Application ...............................................................................67 Opening a new window .......................................................................67 Typing the command ..........................................................................68 Saving the file .......................................................................................69 Running the Application ...............................................................................71 Understanding the Use of Indentation ........................................................72 Adding Comments .........................................................................................74 Understanding comments...................................................................74 Using comments to leave yourself reminders ..................................75 Using comments to keep code from executing ................................75 Loading and Running Existing Applications ..............................................78 Using the command line or terminal window ..................................78 Using the Edit window.........................................................................79 Using the Python Shell window or Python command line .............79 Closing IDLE ...................................................................................................80 Part II: Talking the Talk .............................................. 81 Chapter 5: Storing and Modifying Information . . . . . . . . . . . . . . . . . . . . 83 Storing Information .......................................................................................83 Seeing variables as storage boxes .....................................................84 Using the right box to store the data ................................................84 www.it-ebooks.info

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.