This book is for anyone who wants to understand computer programming. You’ll learn to program in a language that’s used in millions of smartphones, tablets, and PCs. You’ll code along with the book, writing programs to solve real-world problems as you learn the fundamentals of programming using Python 3. You’ll learn about design, algorithms, testing, and debugging, and come away with all the tools you need to produce quality code. In this second edition, we’ve updated almost all the material, incorporating the lessons we’ve learned over the past five years of teaching Python to people new to programming.
This title is currently available in Beta. Buy the eBook now, and you'll be able to download successive releases of the eBook as the authors add material and correct mistakes. You'll get the final eBook when the book is finished.
If you buy the combo pack (Beta eBook + finished Paper Book) now, you'll get the Beta eBook immediately. You'll get the finished paper book when it's released (we're currently estimating 2013-08-01, but these dates can change).
About this Book
- 350 pages (est)
- Release: B5.0 (2013-05-16)
- ISBN: 978-1-93778-545-1
You don’t need any programming experience to get started. First, you’ll get a detailed introduction to Python and to programming. You’ll find out exactly what happens when your programs are executed. Through real-world examples, you’ll learn how to work with numbers, text, big data sets, and files. Then you’ll see how to create and use your own data types.
The incremental examples show you the steps and missteps that happen while developing programs, so you know what to expect when you tackle a problem on your own. Inspired by “How to Design Programs” (HtDP), you’ll learn a six-step recipe for designing functions, which helps you as you start to learn the concepts—and becomes an integral part of writing programs by the end.
As you learn to use the fundamental programming tools in the first half of the book, you’ll see how to document and organize your code so that you and other programmers can more easily read and understand it. Beyond the basics, you’ll learn how to ensure that your programs are reliable, and how to work with databases, download data from the web automatically, and build user interfaces. Most importantly, you’ll learn how to think like a professional programmer.
What You Need
You’ll need to download Python 3, available from python.org. With that download comes IDLE, the editor we use for writing and running Python programs. (If you use Linux, you may need to install Python 3 and IDLE separately.)
Contents and Extracts
This book is currently in beta, so the contents and extracts will change as the book is developed.
- What’s Programming?
- Programs and Programming
- What’s a Programming Language?
- What’s a Bug?
- The Difference Between Brackets, Braces, and Parentheses
- Installing Python
- For Instructors: How This Book is Organized
- What You’ll See in This Book
- Hello, Python excerpt
- How Does a Computer Run a Python Program?
- Expressions and Values: Arithmetic in Python
- What Is a Type?
- Variables and Computer Memory: Remembering Values
- How Python Tells You Something Went Wrong
- A single statement that spans multiple lines
- Describing Code
- Making Code Readable
- Programs, Statements, Expressions, and Variables
- Designing and Using Functions
- Functions that Python Provides
- Memory Addresses: How Python Keeps Track of Values
- Defining our Own Functions
- Tracing Function Calls in the Memory Model
- Designing New Functions: a Recipe
- Writing and Running a Program
- Omitting a return Statement: None
- What Did You Call That?
- Working with Text excerpt
- Creating Strings of Characters
- Using Special Characters in Strings
- Creating a Multiline String
- Printing Information
- Getting Information from the Keyboard
- Quotes from the String Chapter
- Making Choices
- A Boolean Type
- Choosing Which Statements to Execute
- Remembering Results of Boolean Expression Evaluation
- You Learned About Booleans: True or False?
- A Modular Approach to Program Organization
- Importing Modules
- Defining Your Own Modules
- Testing Your Code Semi-Automatically
- Tips for Grouping Your Functions
- Organizing Our Thoughts
- Using Methods
- Modules, Classes, and Methods
- Calling Methods the Object-Oriented Way
- Exploring String Methods
- What Are Those Underscores?
- A Methodical Review
- Storing Collections of Data Using Lists
- Storing and Accessing Data in Lists
- Modifying Lists
- Operations on Lists
- Slicing Lists
- Aliasing: What’s in a Name?
- List Methods
- Working With a List of Lists
- A Summary List
- Repeating Code Using Loops
- Processing Items in a List
- Processing Characters in Strings
- Looping Over a Range of Numbers
- Nesting Loops in Loops
- Looping until a Condition Is Reached
- Repetition Based On User Input
- Controlling Loops Using break and continue
- Repeating What You’ve Learned
- Reading and Writing Files
- Storing Data Using Other Collection Types
- Storing Data Using Sets
- Storing Data Using Tuples
- Storing Data Using Dictionaries
- Inverting a Dictionary
- Comparing Collections
- A Collection of New Information
- Designing Programs
- Searching and Sorting excerpt
- Searching a List
- Binary Search
- More Efficient Sorting Algorithms
- Mergesort: An NlogN Algorithm
- Sorting Out What You Learned
- Object-Oriented Programming
- Testing and Debugging
- Graphical User Interfaces
- The IDLE Development Environment