Skip to main content
main-content
Top

About this book

Move from zero knowledge of programming to comfortably writing small to medium-sized programs in Python. Fully updated for Python 3, with code and examples throughout, the book explains Python coding with an accessible, step-by-step approach designed to bring you comfortably into the world of software development.

Real–world analogies make the material understandable, with a wide variety of well-documented examples to illustrate each concept. Along the way, you’ll develop short programs through a series of coding challenges that reinforce the content of the chapters.

Learn to Program with Python 3 guides you with material developed in the author's university computer science courses. The author's conversational style feels like you're working with a personal tutor. All material is thoughtfully laid out, each lesson building on previous ones.

What You'll Learn

Understand programming basics with Python, based on material developed in the author's college coursesLearn core concepts: variables, functions, conditionals, loops, lists, strings, and more

Explore example programs including simple games you can program and customizeBuild modules to reuse your own codeWho This Book Is For

This book assumes no prior programming experience, and would be appropriate as text for a high school or college introduction to computer science.

Table of Contents

Chapter 1. Getting Started

Abstract
Congratulations! You have made a wise decision. No, not the decision to buy this book, although I think that will turn out to be a wise decision also. I mean you have made a wise decision to learn the basics of computer programming using the Python language.
Irv Kalb

Chapter 2. Variables and Assignment Statements

Abstract
This chapter covers the following topics:
  • A sample Python program
  • Building blocks of programming
  • Four types of data
  • What a variable is
  • Rules for naming variables
  • Giving a variable a value with an assignment statement
  • A good way to name variables
  • Special Python keywords
  • Case sensitivity
  • More complicated assignment statements
  • Print statements
  • Basic math operators
  • Order of operations and parentheses
  • A few small sample programs
  • Additional naming conventions
  • How to add comments in a program
  • Use of “whitespace”
  • Errors in programs
Irv Kalb

Chapter 3. Built-in Functions

Abstract
Just as Python has a number of built-in operators (such as + for addition, - for subtraction, * for multiplication, and so on), it also comes with a number of what are called built-in functions.
Irv Kalb

Chapter 4. User-Defined Functions

Abstract
Software is a detailed set of instructions that tell the computer what to do. There are numerous examples where we, as humans, follow a set of such instructions. As a simple example, many pieces of furniture from IKEA come with a set of high-level instructions in the form of pictures. When creating these instructions, the people at IKEA assume a certain level of basic knowledge of how to use tools, such as a wrench, a screwdriver, a hammer, and so on.
Irv Kalb

Chapter 5. if, else, and elif Statements

Abstract
All the code we have looked at so far has essentially been linear. That is, execution of the code starts from the top and goes straight through to the bottom. The only change to this linear nature of execution is when we make a function call. Doing that transfers control to the function, but all the code inside a function also goes straight through from top to bottom. But one of the most powerful things about code is the ability to make a decision and to take a path based on that decision.
Irv Kalb

Chapter 6. Loops

Abstract
In this chapter, we’ll build a Guess the Number program. The computer will pick a random number between 1 and 20, and the user will have five attempts to guess the number. For every incorrect guess, the computer will let the user know if the correct answer is higher or lower than the user’s guess. If the user doesn’t guess the answer in five attempts, the program will tell the user what the number was.
Irv Kalb

Chapter 7. Lists

Abstract
Prior to this chapter, we’ve talked about four types of data: integer, float, string, and Boolean. But imagine that you want to represent a lot of data—for example, the names of all the students in a class, or better yet, the names of all students in a school, or city, or state. So far, our definition of a variable allows us to only represent a single piece of data. Therefore, if we wanted to represent a group of students’ names, we would do something like this: student1 = 'Joe Schmoe' student2 = 'Sally Smith' student3 = 'Henry Jones' student4 = 'Betty Johnson' student5 = 'Chris Smith'
Irv Kalb

Chapter 8. Strings

Abstract
Other than using them to nicely format output, we haven’t talked much about strings. In this chapter and the next two chapters, we get heavily into strings. I'll show you how to manipulate them and find smaller strings within larger strings.
Irv Kalb

Chapter 9. File Input/Output

Abstract
In every program we have talked about so far, when the program ends, the computer forgets everything that happened in the program. Every variable you created, every string you used, every Boolean, every list—it’s all gone. But what if you want to keep some of the data you generate in a program and save it for when you run the program later? Or maybe you want to save some data so that a different program could use the data you generated.
Irv Kalb

Chapter 10. Internet Data

Abstract
In the previous two chapters, we discussed different ways to get and manipulate strings. That makes this our third chapter on strings. Earlier, I talked about how a program can get text input from the user by using a call to input. In the previous chapter, I showed how a program could get data from and save data to a file. But there is another place where programs can get text data from: the Internet!
Irv Kalb

Chapter 11. Data Structures

Abstract
Let’s start this chapter with a definition.
Irv Kalb

Chapter 12. Where to Go from Here

Abstract
As I said in Chapter 1, this book is not intended to be comprehensive. Instead, the goal is to provide you with a general understanding of programming using the Python language. The good news is that if you have made it this far, you should have a solid understanding of most of the syntax and constructs of Python. However, the more exciting news (if you want to look at it that way) is that there is much more to explore.
Irv Kalb
Additional information