Python 3 For Absolute Beginners - UMass

3y ago
98 Views
17 Downloads
1.96 MB
301 Pages
Last View : 2d ago
Last Download : 3m ago
Upload by : Elisha Lemon
Transcription

Python 3 for AbsoluteBeginners Tim Hall and J-P Stacey

Python 3 for Absolute BeginnersCopyright 2009 by Tim Hall and J-P StaceyAll 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 retrievalsystem, without the prior written permission of the copyright owner and the publisher.ISBN-13 (pbk): 978-1-4302-1632-2ISBN-13 (electronic): 978-1-4302-1633-9Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1Trademarked names may appear in this book. Rather than use a trademark symbol with everyoccurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit ofthe trademark owner, with no intention of infringement of the trademark.Lead Editor: Matthew MoodieTechnical Reviewer: Duncan ParkesAdditional material: Dr. J. Burton BrowningEditorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Tony Campbell, GaryCornell, Jonathan Gennick, Michelle Lowman, Matthew Moodie, Jeffrey Pepper, FrankPohlmann, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom WelshProject Managers: Beth Christmas and Debra KellyCopy Editor: Heather LangCompositor: LaurelTechIndexer: BIM Indexing and e-ServicesArtist: April MilneDistributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor,New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-ny@springer-sbm.com, orvisit http://www.springeronline.com.For information on translations, please e-mail info@apress.com, or visit http://www.apress.com.Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use.eBook versions and licenses are also available for most titles. For more information, reference ourSpecial Bulk Sales–eBook Licensing web page at http://www.apress.com/info/bulksales.The information in this book is distributed on an “as is” basis, without warranty. Although everyprecaution has been taken in the preparation of this work, neither the author(s) nor Apress shall haveany liability to any person or entity with respect to any loss or damage caused or alleged to be causeddirectly or indirectly by the information contained in this work.The source code for this book is available to readers at http://www.apress.com.

Contents at a Glance Contents . v About the Author . xi About the Technical Reviewer . xii Chapter 1: Introducing Python .1 Chapter 2: Designing Software.9 Chapter 3: Variables and Data Types.27 Chapter 4: Making Choices.49 Chapter 5: Using Lists.75 Chapter 6: Functions .101 Chapter 7: Working with Text.125 Chapter 8: Executable Files, Organization, and Python on the Web.161 Chapter 9: Classes.181 Chapter 10: Exceptions.221 Chapter 11: Reusing Code with Modules and Packages .241 Chapter 12: Simple Windowed Applications.261 Index.283iii

CONTENTSContents About the Author . xi About the Technical Reviewer . xii Chapter 1: Introducing Python .1Running Python on Various Systems .1Learning While Having Fun .4Introducing the Interactive Shell.4Choosing to Code with a Text Editor.5Choosing to Code with an Integrated Development Environment.5Getting Started with Programming .5Creating Your Own Help Files .6Jargon Busting.6Summary .7 Chapter 2: Designing Software.9Designing Your Own Software (Why Bother?).9Identifying the Problem.10Creating Your Wish List.12Devising a Solution .13Breaking Down the Solution into Steps .15Jargon Busting.24Summary .25 Chapter 3: Variables and Data Types.27Choosing Good Identifiers.27Creating Variables and Assigning Values.28Recognizing Different Types of Variables .29Jargon Busting.45v

CONTENTSSummary .47 Chapter 4: Making Choices.49Comparing Things.49Taking Control of the Process.55Dealing with Logical Errors.57Using Conditional Code in the Application .61Now Repeat That .65Jargon Busting.73Summary .74 Chapter 5: Using Lists.75Working with Python Data Structures.75Tuples .79Lists .80Sets.85Dictionaries.86A Simple Role-Playing Combat Game .89Jargon Busting.99Summary .100 Chapter 6: Functions .101Accessing Privileged Information .101Working with Variable Scope.105Refactoring rpcombat.py to Reduce Repetition .108Jargon Busting.123Summary .124 Chapter 7: Working with Text.125Strings and Things.125Matching Patterns Using Regular Expressions .135Using Files .141Applications .145Jargon Busting.159Summary .160vi

CONTENTS Chapter 8: Executable Files, Organization, and Python on the Web.161Making Programs Executable as Stand-Alone Applications .161Organizing Your Project .164Writing Stylish Code.165Importing Modules.170Using exec() and eval().172Putting Python on the Web .173Jargon Busting.179Summary .179 Chapter 9: Classes.181Empowering objects .182When Should Classes Be Used? .185Customizing Classes.191Application .200Jargon Busting.219Summary .220 Chapter 10: Exceptions.221When Something Goes Wrong .221Classes of Exceptions .224A Final Note on Pythonic Exception Handling .238Jargon Busting.239Summary .240 Chapter 11: Reusing Code with Modules and Packages .241Understanding Python Modules .

Python as his main programming language, primarily as a means for creative ends, because it is easy to read and fun to learn. J-P Stacey has been a senior developer at Torchbox Ltd since 2005, building and maintaining (among other things) Python, Django, and Drupal applications. He organizes the Oxford Geek Nights and gets involved in tuition and seminars at Torchbox. In his spare time he .

Related Documents:

Python Programming for the Absolute Beginner Second Edition. CONTENTS CHAPTER 1 GETTING STARTED: THE GAME OVER PROGRAM 1 Examining the Game Over Program 2 Introducing Python 3 Python Is Easy to Use 3 Python Is Powerful 3 Python Is Object Oriented 4 Python Is a "Glue" Language 4 Python Runs Everywhere 4 Python Has a Strong Community 4 Python Is Free and Open Source 5 Setting Up Python on .

Python 2 versus Python 3 - the great debate Installing Python Setting up the Python interpreter About virtualenv Your first virtual environment Your friend, the console How you can run a Python program Running Python scripts Running the Python interactive shell Running Python as a service Running Python as a GUI application How is Python code .

Python is readable 5 Python is complete—"batteries included" 6 Python is cross-platform 6 Python is free 6 1.3 What Python doesn't do as well 7 Python is not the fastest language 7 Python doesn't have the most libraries 8 Python doesn't check variable types at compile time 8 1.4 Why learn Python 3? 8 1.5 Summary 9

Bruksanvisning för bilstereo . Bruksanvisning for bilstereo . Instrukcja obsługi samochodowego odtwarzacza stereo . Operating Instructions for Car Stereo . 610-104 . SV . Bruksanvisning i original

"Python for Programmers" where we teach you how to convert what you know from other programming languages to Python. This course is based around Python version 3. Python has recently undergone a change from Python 2 to Python 3 and there are some incompatibilities between the two versions. The older versions of this course were based around .

site "Python 2.x is legacy, Python 3.x is the present and future of the language". In addition, "Python 3 eliminates many quirks that can unnecessarily trip up beginning programmers". However, note that Python 2 is currently still rather widely used. Python 2 and 3 are about 90% similar. Hence if you learn Python 3, you will likely

There are currently two versions of Python in use; Python 2 and Python 3. Python 3 is not backward compatible with Python 2. A lot of the imported modules were only available in Python 2 for quite some time, leading to a slow adoption of Python 3. However, this not really an issue anymore. Support for Python 2 will end in 2020.

Hands-On Python A Tutorial Introduction for Beginners Python 3.1 Version Dr. Andrew N. Harrington . 4.3. CGI-DynamicWebPages 131 4.4. Summary 138 3. CHAPTER 1 Beginning With Python 1.1. Context . (To load Python see Section 1.1.2) On a Mac or Linux computer enough of Python comes .