Python 3 for Absolute Beginners (eBook)
300 Seiten
Apress (Verlag)
978-1-4302-1633-9 (ISBN)
There are many more people who want to study programming other than aspiring computer scientists with a passing grade in advanced calculus. This guide appeals to your intelligence and ability to solve practical problems, while gently teaching the most recent revision of the programming language Python.
You can learn solid software design skills and accomplish practical programming tasks, like extending applications and automating everyday processes, even if you have no programming experience at all. Authors Tim Hall and J-P Stacey use everyday language to decode programming jargon and teach Python 3 to the absolute beginner.
Tim Hall currently provides front-line support for 64 Studio. He has also written newbie tutorials for Linux User and Developer magazine in between more mundane system admin and web authoring jobs. Tim has released albums and performed as a musician and songwriter, both solo and in collaboration with other artists. He has been further honored as the holder of the Bardic chair of Glastonbury between 2005 and 2007. Tim uses Python as his main programming language, primarily as a means for creative ends, because it is easy to read and fun to learn.
There are many more people who want to study programming other than aspiring computer scientists with a passing grade in advanced calculus. This guide appeals to your intelligence and ability to solve practical problems, while gently teaching the most recent revision of the programming language Python.You can learn solid software design skills and accomplish practical programming tasks, like extending applications and automating everyday processes, even if you have no programming experience at all. Authors Tim Hall and J P Stacey use everyday language to decode programming jargon and teach Python 3 to the absolute beginner.
Tim Hall currently provides front-line support for 64 Studio. He has also written newbie tutorials for Linux User and Developer magazine in between more mundane system admin and web authoring jobs. Tim has released albums and performed as a musician and songwriter, both solo and in collaboration with other artists. He has been further honored as the holder of the Bardic chair of Glastonbury between 2005 and 2007. Tim uses Python as his main programming language, primarily as a means for creative ends, because it is easy to read and fun to learn.
Contents at a Glance 4
Table of Contents 5
About the Author 9
About the Technical Reviewer 10
Chapter 1: Introducing Python 11
Running Python on Various Systems 11
Installing on Windows 12
Installing on Other Systems 12
Choosing the Right Python Version 12
Understanding the Jargon 13
Learning While Having Fun 14
Introducing the Interactive Shell 14
Choosing to Code with a Text Editor 15
Choosing to Code with an Integrated Development Environment 15
Getting Started with Programming 15
Creating Your Own Help Files 16
Jargon Busting 16
Summary 17
Chapter 2: Designing Software 18
Designing Your Own Software (Why Bother?) 18
Asking the Right Questions 19
Using Python to Solve Problems 19
Identifying the Problem 19
What Do You Want the Software to Do? 20
Who Will Be Using It? 20
What System Will Users Be Running It On? 21
Creating Your Wish List 21
Talking to Potential Users 21
Watching Users Perform the Task at Hand 22
Compiling User Stories 22
Devising a Solution 22
Understanding the Problem 22
Knowing What the Software Needs to Do 23
Considering Other Needs or Limitations 23
Defining Acceptable Results 23
Considering Maintenance 23
Breaking Down the Solution into Steps 24
Organizing the Tasks into Steps 25
Using Indentation and Subgroups 26
Refining Each Line of Your Pseudocode Until a Solution Is Reached 26
Coding the Design 27
Turning the Design into Executable Code 27
Further Refining the Design 28
Using functions 28
Testing the Design 29
Detecting and correcting coding errors 30
Noting Modifications, Extensions, and Enhancements 31
Documenting the Solution 31
Jargon Busting 33
Summary 34
Chapter 3: Variables and Data Types 35
Choosing Good Identifiers 35
Python Keywords 35
Following the Naming Rules 36
Creating Variables and Assigning Values 36
Recognizing Different Types of Variables 37
Working with Dynamic Typing 37
In the Beginning Was the Void 39
Joining Up Text Fragments 39
Using Quotes 40
Nesting Quotes 41
Escaping Sequences 42
Using Special Whitespace Characters 42
The More Strings Change the More They Stay the Same 43
Creating a Text Application 43
Working with Numbers 45
Using Binary: Computers Can Only Count to One 45
Bits and Bytes 45
Using Booleans: Truth or Dare 45
Using Whole Numbers (Integers) 46
Performing Basic Mathematical Operations 46
Understanding Operator Precedence 47
Dividing Numbers 47
Working with Fractions and Floats 48
Converting One Type into Another 48
Working with Base 8 (Octal) and Base 16 (Hexadecimal) 49
Creating a Number Application 51
Jargon Busting 53
Summary 55
Chapter 4: Making Choices 56
Comparing Things 56
Manipulating Boolean Values 59
Combining Conditional Expressions 60
Using Assignment Operators 60
Understanding Operator Precedence 61
Taking Control of the Process 62
Using the for Statement 76
Dealing with Logical Errors 64
Using Conditional Code in the Application 68
Now Repeat That 72
Looping with the while Statement 72
Now Get Out of That 74
Nesting Conditional Statements 76
Jargon Busting 80
Summary 81
Chapter 5: Using Lists 82
Working with Python Data Structures 82
Accessing the items in a sequence 82
If You’re Not on the List, You Can’t Come In 84
Tuples 86
Creating a Tuple 86
Changing the Values in a Tuple 87
Lists 87
Creating a List 87
Modifying a List 87
Stacks and Queues 89
Sorting Lists 89
Multidimensional Lists 90
Processing Large Amounts of Data Easily 90
List Comprehensions 91
Sets 92
Dictionaries 93
Defining Dictionaries 93
Deleting Items 95
Sorting Dictionaries 96
Using Dictionaries 96
A Simple Role-Playing Combat Game 96
Jargon Busting 106
Summary 107
Chapter 6: Functions 108
Accessing Privileged Information 108
Defining Functions 108
Sending Out Invitations 109
Passing an Unknown Number of Values into the Function 110
Using docstrings to Document Your Function 111
Working with Variable Scope 112
Understanding Scope 112
Using the global Statement 114
Manipulating Lists and Dictionaries 115
Refactoring rpcombat.py to Reduce Repetition 115
Cutting Out the Waffle 116
Keeping Your Code Readable 118
The Matrix Refactored 120
Jargon Busting 130
Summary 131
Chapter 7: Working with Text 132
Strings and Things 132
Splitting Strings 133
Joining Strings, or Avoiding Concatenation 134
Changing Case 135
Simple Methods of Formatting 136
Advanced Formatting 136
Format Specification 137
Editing Strings 141
Finding Strings 141
Matching Patterns Using Regular Expressions 142
Matching Subpatterns 144
Matching Character Sets and Alternatives 145
Finding Patterns at the Beginning or End of a String 145
Creating a Regular Expression Object 146
Letting the Characters Escape 146
Manipulating Strings Using Regular Expressions 146
Using Files 148
Opening Files 148
Modes and Buffers 149
Reading from and Writing to Files 149
Finding Your Way Around Files 150
Closing Files 151
Applications 152
Converting Text 152
Story 154
Checking and Correcting Styles 154
Formatting Data 161
Storing Data 163
Jargon Busting 166
Summary 167
Chapter 8: Executable Files, Organization, and Python on the Web 168
Making Programs Executable as Stand-Alone Applications 168
Organizing Your Project 171
Writing Stylish Code 172
Becoming More Pythonic 173
Importing Modules 177
Using exec() and eval() 179
Putting Python on the Web 180
Creating a Quick CGI Form 184
Jargon Busting 186
Summary 186
Chapter 9: Classes 187
Empowering objects 188
Defining Classes 188
Who Is self? 189
Determining an Object’s Type 190
Namespaces and Why We Need Them 191
When Should Classes Be Used? 191
Parents and Children—Inheritance 195
Using Methods 196
Customizing Classes 197
Constructors 198
Customizing Output 199
Emulating Existing Types 200
Properties 202
Customizing Attribute Access 203
Emulating Numeric Types 203
Application 206
Jargon Busting 225
Summary 226
Chapter 10: Exceptions 227
When Something Goes Wrong 227
Handling Simple Exceptions 228
Using the try Statement with an except Clause in Python 228
Classes of Exceptions 230
Exception objects and the hierarchy of classes 230
Creating and Raising an Exception Object 231
Creating Your Own Exception Classes 233
Accessing Properties of the Raised Exception 235
Implementing Complex Error Handling 237
Using finally to Clean Up After a Problem 237
Putting Everything Together with else 238
Using the Traceback If All Else Fails 240
Exception Chaining and Tracebacks 241
A Final Note on Pythonic Exception Handling 244
Jargon Busting 245
Summary 246
Chapter 11: Reusing Code with Modules and Packages 247
Understanding Python Modules 247
Creating Your First Module 248
Using Your Module in Another Program 249
Everyday Module Usage 250
Flexible Importing 250
Structuring Your Modules 252
Advanced Module Behavior 255
Reloading Module Changes Dynamically 255
Python Module Internals 256
Combining Modules into Packages 258
Understanding Packages 258
Building a Pirate-Speak Package 258
The Universe of Python packages 260
Standard Modules 260
Installing Contributed Packages 260
Three Examples from the Python Universe 262
csv 262
datetime 263
Beautiful Soup and urllib 264
A Package for Everything—Eventually 265
Jargon Busting 265
Summary 266
Chapter 12: Simple Windowed Applications 267
Using Tkinter 267
Saying “Hello” with PyGTK 271
Catching Signals 273
Building Complex Interfaces 274
Creating the GUI 275
Making the Commands Do Something Useful 278
Using Glade and tepache to Build Interfaces 285
Jargon Busting 288
Summary 288
Index 289
Erscheint lt. Verlag | 10.3.2010 |
---|---|
Zusatzinfo | 300 p. |
Verlagsort | Berkeley |
Sprache | englisch |
Themenwelt | Informatik ► Programmiersprachen / -werkzeuge ► Python |
Mathematik / Informatik ► Informatik ► Theorie / Studium | |
Mathematik / Informatik ► Informatik ► Web / Internet | |
Schlagworte | Calculus • Computer • organization • programming • Programming language |
ISBN-10 | 1-4302-1633-6 / 1430216336 |
ISBN-13 | 978-1-4302-1633-9 / 9781430216339 |
Haben Sie eine Frage zum Produkt? |
Größe: 1,8 MB
DRM: Digitales Wasserzeichen
Dieses eBook enthält ein digitales Wasserzeichen und ist damit für Sie personalisiert. Bei einer missbräuchlichen Weitergabe des eBooks an Dritte ist eine Rückverfolgung an die Quelle möglich.
Dateiformat: PDF (Portable Document Format)
Mit einem festen Seitenlayout eignet sich die PDF besonders für Fachbücher mit Spalten, Tabellen und Abbildungen. Eine PDF kann auf fast allen Geräten angezeigt werden, ist aber für kleine Displays (Smartphone, eReader) nur eingeschränkt geeignet.
Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen dafür einen PDF-Viewer - z.B. den Adobe Reader oder Adobe Digital Editions.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen dafür einen PDF-Viewer - z.B. die kostenlose Adobe Digital Editions-App.
Zusätzliches Feature: Online Lesen
Dieses eBook können Sie zusätzlich zum Download auch online im Webbrowser lesen.
Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.
aus dem Bereich