Beginning Programming With Python For Dummies , 2nd

Transcription

BeginningProgrammingwith Python 2nd Editionby John Paul Mueller

Beginning Programming with Python For Dummies , 2nd EditionPublished by: John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030-5774, www.wiley.comCopyright 2018 by John Wiley & Sons, Inc., Hoboken, New JerseyPublished simultaneously in CanadaNo part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by anymeans, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections107 or 108 of the 1976 United States Copyright Act, without the prior written permission of the Publisher. Requests tothe Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 RiverStreet, 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 relatedtrade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and may not be used without writtenpermission. Python is a registered trademark of Python Software Foundation Corporation. All other trademarks are theproperty of their respective owners. John Wiley & Sons, Inc. is not associated with any product or vendor mentioned inthis book.LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NOREPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTSOF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIESOF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES ORPROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOREVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGEDIN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE ISREQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THEPUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT ANORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OFFURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATIONTHE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERSSHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEAREDBETWEEN 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 withinthe U.S. at 877-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002. For technical support, please es.Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included withstandard print versions of this book may not be included in e-books or in print-on-demand. If this book refers tomedia such as a CD or DVD that is not included in the version you purchased, you may download this material athttp://booksupport.wiley.com. For more information about Wiley products, visit www.wiley.com.Library of Congress Control Number: 2017964018ISBN 978-1-119-45789-3; ISBN 978-1-119-45787-9 (ebk); ISBN 978-1-119-45790-9 (ebk)Manufactured in the United States of America10 9 8 7 6 5 4 3 2 1

Contents at a GlanceIntroduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Part 1: Getting Started with Python. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5CHAPTER 1:CHAPTER 2:CHAPTER 3:CHAPTER 4:CHAPTER 5:Talking to Your Computer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7Getting Your Own Copy of Python. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21Interacting with Python. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37Writing Your First Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55Working with Anaconda. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83Part 2: Talking the Talk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .101Storing and Modifying Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .CHAPTER 7: Managing Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .CHAPTER 8: Making Decisions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .CHAPTER 9: Performing Repetitive Tasks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .CHAPTER 10: Dealing with Errors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .103113135151165Part 3: Performing Common Tasks. . . . . . . . . . . . . . . . . . . . . . . . . . .195Interacting with Packages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .CHAPTER 12: Working with Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .CHAPTER 13: Managing Lists. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .CHAPTER 14: Collecting All Sorts of Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .CHAPTER 15: Creating and Using Classes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .197225243261281Part 4: Performing Advanced Tasks. . . . . . . . . . . . . . . . . . . . . . . . . .303CHAPTER 6:CHAPTER 11:Storing Data in Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305CHAPTER 17: Sending an Email. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323CHAPTER 16:Part 5: The Part of Tens. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .341Ten Amazing Programming Resources. . . . . . . . . . . . . . . . . . . . . . . . . . .Ten Ways to Make a Living with Python. . . . . . . . . . . . . . . . . . . . . . . . . .CHAPTER 20: Ten Tools That Enhance Your Python Experience. . . . . . . . . . . . . . . . . .CHAPTER 21: Ten (Plus) Libraries You Need to Know About. . . . . . . . . . . . . . . . . . . . .343353361371Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .379CHAPTER 18:CHAPTER 19:

Table of ContentsINTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1About This Book. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Foolish Assumptions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Icons Used in This Book. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Beyond the Book. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Where to Go from Here . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12334PART 1: GETTING STARTED WITH PYTHON. . . . . . . . . . . . . . . . . . . . 5CHAPTER 1:Talking to Your Computer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7Understanding Why You Want to Talk to Your Computer. . . . . . . . . . . . 8Knowing that an Application is a Form of Communication. . . . . . . . . . . 9Thinking about procedures you use daily . . . . . . . . . . . . . . . . . . . . . . 9Writing procedures down. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10Seeing applications as being like any other procedure. . . . . . . . . . 11Understanding that computers take things literally. . . . . . . . . . . . . 11Defining What an Application Is . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11Understanding that computers use a special language . . . . . . . . . 12Helping humans speak to the computer. . . . . . . . . . . . . . . . . . . . . . 12Understanding Why Python Is So Cool. . . . . . . . . . . . . . . . . . . . . . . . . . . 14Unearthing the reasons for using Python . . . . . . . . . . . . . . . . . . . . . 14Deciding how you can personally benefit from Python. . . . . . . . . . 15Discovering which organizations use Python . . . . . . . . . . . . . . . . . . 16Finding useful Python applications. . . . . . . . . . . . . . . . . . . . . . . . . . . 17Comparing Python to other languages . . . . . . . . . . . . . . . . . . . . . . . 18CHAPTER 2:Getting Your Own Copy of Python. . . . . . . . . . . . . . . . . . . . . 21Downloading the Version You Need. . . . . . . . . . . . . . . . . . . . . . . . . . . . .Installing Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Working with Windows. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Working with the Mac. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Working with Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Accessing Python on Your Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using the Mac . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using Linux. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Testing Your Installation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Table of Contents21242527283132343535v

CHAPTER 3:Interacting with Python. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37Opening the Command Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Starting Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using the command line to your advantage. . . . . . . . . . . . . . . . . . .Using Python environment variables to your advantage . . . . . . . .Typing a Command. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Telling the computer what to do. . . . . . . . . . . . . . . . . . . . . . . . . . . . .Telling the computer you’re done. . . . . . . . . . . . . . . . . . . . . . . . . . . .Seeing the result . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Getting into help mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Asking for help. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Leaving help mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Obtaining help directly. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Closing the Command Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .CHAPTER 4:3838394143434444464647495051Writing Your First Application. . . . . . . . . . . . . . . . . . . . . . . . . . 55Understanding Why IDEs Are Important. . . . . . . . . . . . . . . . . . . . . . . . . 56Creating better code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56Debugging functionality. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56Defining why notebooks are useful . . . . . . . . . . . . . . . . . . . . . . . . . . 57Obtaining Your Copy of Anaconda. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58Obtaining Analytics Anaconda. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58Installing Anaconda on Linux. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59Installing Anaconda on MacOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60Installing Anaconda on Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61Downloading the Datasets and Example Code. . . . . . . . . . . . . . . . . . . . 64Using Jupyter Notebook. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64Defining the code repository. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65Creating the Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71Understanding cells. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .71Adding documentation cells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74Other cell content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75Understanding the Use of Indentation . . . . . . . . . . . . . . . . . . . . . . . . . . 75Adding Comments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77Understanding comments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78Using comments to leave yourself reminders . . . . . . . . . . . . . . . . . 79Using comments to keep code from executing . . . . . . . . . . . . . . . . 80Closing Jupyter Notebook. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .80viBeginning Programming with Python For Dummies

CHAPTER 5:Working with Anaconda. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83Downloading Your Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Working with Checkpoints. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Defining the uses of checkpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . .Saving a checkpoint. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Restoring a checkpoint. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Manipulating Cells. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Adding various cell types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Splitting and merging cells. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Moving cells around . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Running cells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Toggling outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Changing Jupyter Notebook’s Appearance . . . . . . . . . . . . . . . . . . . . . . .Finding commands using the Command Palette . . . . . . . . . . . . . . .Working with line numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using the Cell Toolbar features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Interacting with the Kernel. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Obtaining Help. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using the Magic Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Viewing the Running Processes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .84858586868687878888909091929394959799PART 2: TALKING THE TALK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .101Storing and Modifying Information . . . . . . . . . . . . . . . . .103Storing Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Seeing variables as storage boxes . . . . . . . . . . . . . . . . . . . . . . . . . .Using the right box to store the data. . . . . . . . . . . . . . . . . . . . . . . .Defining the Essential Python Data Types. . . . . . . . . . . . . . . . . . . . . . .Putting information into variables . . . . . . . . . . . . . . . . . . . . . . . . . .Understanding the numeric types . . . . . . . . . . . . . . . . . . . . . . . . . .Understanding Boolean values. . . . . . . . . . . . . . . . . . . . . . . . . . . . .Understanding strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Working with Dates and Times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .104104104105105106110110111Managing Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .113Controlling How Python Views Data. . . . . . . . . . . . . . . . . . . . . . . . . . . .Making comparisons. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Understanding how computers make comparisons . . . . . . . . . . .Working with Operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Defining the operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Understanding operator precedence. . . . . . . . . . . . . . . . . . . . . . . .114114115115116122CHAPTER 6:CHAPTER 7:Table of Contentsvii

Creating and Using Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123Viewing functions as code packages. . . . . . . . . . . . . . . . . . . . . . . . .124Understanding code reusability . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124Defining a function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125Accessing functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126Sending information to functions. . . . . . . . . . . . . . . . . . . . . . . . . . . 127Returning information from functions. . . . . . . . . . . . . . . . . . . . . . . 131Comparing function output. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132Getting User Input. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132CHAPTER 8:CHAPTER 9:CHAPTER 10:viiiMaking Decisions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .135Making Simple Decisions by Using the if Statement . . . . . . . . . . . . . .Understanding the if statement . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using the if statement in an application . . . . . . . . . . . . . . . . . . . . .Choosing Alternatives by Using the if. . .else Statement. . . . . . . . . . .Understanding the if. . .else statement . . . . . . . . . . . . . . . . . . . . . .Using the if. . .else statement in an application . . . . . . . . . . . . . . .Using the if. . .elif statement in an application . . . . . . . . . . . . . . . .Using Nested Decision Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using multiple if or if. . .else statements . . . . . . . . . . . . . . . . . . . . .Combining other types of decisions. . . . . . . . . . . . . . . . . . . . . . . . .136136137141141142143146146148Performing Repetitive Tasks . . . . . . . . . . . . . . . . . . . . . . . . .151Processing Data Using the for Statement . . . . . . . . . . . . . . . . . . . . . . .Understanding the for statement. . . . . . . . . . . . . . . . . . . . . . . . . . .Creating a basic for loop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Controlling execution with the break statement . . . . . . . . . . . . . .Controlling execution with the continue statement. . . . . . . . . . . .Controlling execution with the pass clause. . . . . . . . . . . . . . . . . . .Controlling execution with the else statement. . . . . . . . . . . . . . . .Processing Data by Using the while Statement . . . . . . . . . . . . . . . . . .Understanding the while statement. . . . . . . . . . . . . . . . . . . . . . . . .Using the while statement in an application. . . . . . . . . . . . . . . . . .Nesting Loop Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .152152153153156157158159160161162Dealing with Errors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .165Knowing Why Python Doesn’t Understand You . . . . . . . . . . . . . . . . . .Considering the Sources of Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Classifying when errors occur. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Distinguishing error types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Catching Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Basic exception handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Handling more specific to less specific exceptions . . . . . . . . . . . .Nested exception handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .166167168169171171183185Beginning Programming with Python For Dummies

Raising Exceptions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Raising exceptions during exceptional conditions. . . . . . . . . . . . .Passing error information to the caller . . . . . . . . . . . . . . . . . . . . . .Creating and Using Custom Exceptions. . . . . . . . . . . . . . . . . . . . . . . . .Using the finally Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .189189190191192PART 3: PERFORMING COMMON TASKS. . . . . . . . . . . . . . . . . . . .195CHAPTER 11:CHAPTER 12:CHAPTER 13:Interacting with Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . .197Creating Code Groupings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Understanding the package types . . . . . . . . . . . . . . . . . . . . . . . . . .Considering the package cache. . . . . . . . . . . . . . . . . . . . . . . . . . . . .Importing Packages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using the import statement. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using the from. . .import statement. . . . . . . . . . . . . . . . . . . . . . . . .Finding Packages on Disk. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Downloading Packages from Other Sources. . . . . . . . . . . . . . . . . . . . .Opening the Anaconda Prompt. . . . . . . . . . . . . . . . . . . . . . . . . . . . .Working with conda packages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Installing packages by using pip . . . . . . . . . . . . . . . . . . . . . . . . . . . .Viewing the Package Content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Viewing Package Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Opening the Pydoc application. . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using the quick-access links. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Typing a search term . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Viewing the results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22Working with Strings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .225Understanding That Strings Are Different. . . . . . . . . . . . . . . . . . . . . . .Defining a character by using numbers. . . . . . . . . . . . . . . . . . . . . .Using characters to create strings . . . . . . . . . . . . . . . . . . . . . . . . . .Creating Stings with Special Characters. . . . . . . . . . . . . . . . . . . . . . . . .Selecting Individual Characters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Slicing and Dicing Strings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Locating a Value in a String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Formatting Strings. . . . . . . . . . . . . . . . .

vi Beginning Programming with Python For Dummies CHAPTER 3: Interacting with Python. . . . . . . . . . . . .