Table of Contents....5
About the Author....12
About the Technical Reviewer....13
Acknowledgments....14
Introduction....15
Chapter 1: Introduction to Computer Programming and Python....20
Programming Language Overview....21
Python Overview....21
How Does Python Differ from Other Programming Languages?....22
The Benefits of Python....22
Examples of Python in the Wild....24
Your First Python Program....25
Installing Python....26
Installing Python on Windows....26
Installing Python on Other Operating Systems....35
In This Episode!....35
Chapter 2: It All Adds Up....37
Operator Precedence....38
Data Types: Know Your Enemy....41
Converting Number Data Types....45
What Are Variables?....47
Superhero Generator 3000....50
In This Episode!....54
Chapter 3: Stringing Things Along....56
Leave Your Comments at the Door....56
Block Commenting....58
Inline Commenting....59
Other Uses for Commenting....59
Texting – Without Your Phone....60
Working with Strings and Variables....62
Longer Strings....64
Strings on Multiple Lines....65
Formatting Strings....65
Introducing a New Weapon to Your Arsenal: Lists....68
Changing Lists....71
Other List Methods....73
In This Episode!....75
Chapter 4: Making Decisions....77
Making Decisions....78
Conditional Statements....79
Behold – The If Statement!....80
Boolean Logic and Comparison Operators....83
Else Statements....85
Else-If Statements....86
Logical Operators....89
Nesting – Not Just for the Birds....92
In This Episode!....95
Chapter 5: Loops and Logic....97
What Are Loops?....97
Limiting Loops....101
For Loops....103
More Fun with For Loops....107
Break, Continue, and Pass Statements....108
In This Episode!....111
Chapter 6: Using What We’ve Learned....114
Creating Your First Real Program....114
Importing Modules....115
Creating Our Variables....116
Defining Our Lists....117
Introductory Text and Accepting Input from the User....117
Creating Suspense!....118
Randomizing Superhero Names....120
A Quick Check-In....122
Randomizing the Superpowers....124
Finishing Our Program....127
The SuperheroGenerator3000 Code – Completed!....129
Chapter 7: Saving Time with Functions, Modules, and Built-Ins....135
Defining Modules....136
Built-Ins....136
Packages....140
Creating Your Own Module....141
Common Built-In Functions....144
String Functions....145
Number Functions....147
Practice Your New Functions....149
String Function Examples....150
Number Function Examples....151
In This Episode!....151
Chapter 8: Using Classes and Objects....153
What Is OOP?....153
What Are Classes (And Will I Be Graded?)....154
What Are Objects....155
Creating Our First Class....155
Creating Our First Object....156
Improving the Superhero Generator 3000!....158
Inheritance, Subclasses, and More!....166
Adding the Bells and Whistles....173
The New and Improved Superhero Generator 3000 Code!....177
In This Episode!....182
Chapter 9: Introducing Other Data Structures....184
More Data Structures....185
What Are Tuples?....186
The Tuple Functions....190
More Fun with Tuples....192
Tuple Examples....196
Working with Dictionaries....198
Dictionary Methods....200
More Fun with Dictionaries....201
Other Dictionary Methods....204
Example Dictionary Code....206
In This Episode!....207
Chapter 10: Python Files....209
Working with Files in Python....210
File Types....212
Creating a Text File in Python Code....213
Reading Files in Python....215
Using readline( ) and readlines( )....217
A Warning About Reading and Writing to Files....218
Appending to Files....219
Working with Directories....221
Bonus Round!....225
FunWithFiles.py Code....226
WorkingWithDirectories.py....228
In This Episode!....229
Chapter 11: Python for Gaming....231
Python for Gaming....232
Types of Games You Can Code in Python....233
Pygame Introduction....233
Installing Pygame....234
Setting Up the Pygame Bare Bones for a Game....235
Adding to Our Game Skeleton....236
Adding Images and Sprites in Pygame....238
Adding Text to Our Pygame Game Window....243
Drawing Shapes in Pygame....247
Adding More Events....250
In This Episode....260
Chapter 12: Animating Games....262
Creating Animations in Pygame....262
Collision Detection: Bouncing Off the Walls....269
Collision Detection: Detecting the Window Boundaries....270
Colliding Two Objects....274
In This Episode!....280
Chapter 13: Error Handling....281
Finding Errors....282
Types of Errors....286
Syntax Errors....286
Logical Errors....287
Exceptions....289
The Try Except Else Block....291
Using Finally....292
Creating Custom Exceptions....293
Logging....295
Debugging Tools in Python....298
One Final Tip for Handling Errors....299
In This Episode!....300
Chapter 14: Python Career....302
Working with Python....304
Career Paths for Python....304
Beta Tester....305
Code Debugger/Bug Locator....305
Data Scientists....306
Software Developer/Software Engineer....306
Video Game Programmer....306
Mobile Development....307
Web Development and Web Applications....308
System Administration....308
Research, Teaching, and More....308
Common Python Interview Questions....309
Can You Tell Me Some of the Key Features of Python?....309
What Is the Difference Between a Tuple and a List....310
What Is Inheritance?....310
How Do You Generate Random Values in Python?....310
How Do You Create a List, Tuple, and Dictionary in Python?....311
What Is the Difference Between a Local Variable and a Global Variable?....311
What Are the Different Data Types Python Offers?....311
What Is a GUI? What Python Library Is Best for GUI Development?....311
How Do You Open a File in Python?....312
How Would You List the Functions of a Module?....312
Other Python Interview Questions....312
Best Programming Practices....313
Follow Style Guides....313
If It’s Broken, Fix It (Now, Not Later)....314
Documentation Is Everything....314
Use Code Repositories and Packages....315
Test Often....315
Choose a Side: Indentation or Spaces....316
Classes Are Great, But Not Everything Needs to Be One....316
The Future of Python....317
Python Terms....318
Index....322
This book, which is designed for middle-school through college-aged students, will arm beginners with solid programming foundations they can carry throughout life. It uses fun and simple language (and programming examples) to teach the fundamentals needed to start the down path of becoming a programmer. Python is a highly flexible language, allowing developers to enter any number of technical fields and is a welcome addition to any resume. With its low learning curve, it makes a great introductory language, as new developers can take the coding fundamentals they learn in Python and apply them to any other language.
The second edition builds upon the foundation of the first book, revising all the chapters where the language has changed, updating the commands, code, and examples to bring it up to date with the current version of Python.
Since Python is the most popular programming language in the world and can be used in conjunctionwith other languages - across multiple platforms - it can increase the reader's ability to qualify for a wider range of jobs than other languages. Finally, Python is fun - something not every programming language can boast!
The book’s target audience is primarily middle school to college aged students looking to learn how to program computers and develop software. Older individuals and computer programmers who know other languages and want to add Python to their repertoire can also benefit from the book.