Skip to main content

About this book

Get started in the world of software development: go from zero knowledge of programming to comfortably writing small to medium-sized programs in Python. Programming can be intimidating (especially when most books on software require you to know and use obscure command line instructions) but it doesn’t have to be that way!

In Learn to Program with Python, author Irv Kalb uses his in-person teaching experience to guide you through learning the Python computer programming language. He uses a conversational style to make you feel as though he is your personal tutor. All material is laid out in a thoughtful manner, each lesson building on previous ones. Many real–world analogies make the material easy to relate to. A wide variety of well-documented examples are provided. Along the way, you’ll develop small programs on your own through a series of coding challenges that reinforce the content of the chapters.

What You Will Learn Learn fundamental programming concepts including: variables and assignment statements, functions, conditionals, loops, lists, strings, file input and output, Internet data, and data structures

Get comfortable with the free IDLE Interactive Development Environment (IDE), which you will use to write and debug all your Python code - no need to use the command line!

Build text-based programs, including a number of simple games

Learn how to re-use code by building your own modules

Use Python's built-in data structures and packages to represent and make use of complex data from the Internet

Who This Book Is For

This book assumes that you have absolutely no prior knowledge about programming. There is no need to learn or use any obscure Unix commands. Students of any age who have had no exposure to programming and are interested in learning to do software development in the Python language. The book can be used as a text book associated with a high school or college introduction to computer science course. Secondly, people who have had exposure to some computer language other than Python, who would like to build good habits for programming in Python.

Table of Contents

Chapter 1. Getting Started

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 that you have made a good decision to learn the basics of computer programming using the Python language.
Irv Kalb

Chapter 2. Variables and Assignment Statements

This chapter covers the following topics:
Irv Kalb

Chapter 3. Built-in Functions

Just as Python has a number of built-in operators (such as the plus for addition, minus for subtraction, asterisk for multiplication, etc.), Python also has a number of what are called built-in functions.
Irv Kalb

Chapter 4. User-Defined Functions

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 forth. But using each of these tools could be broken down into simpler steps. Using a hammer could be broken down into grip the hammer by the handle, hold the nail perpendicular to the surface, tap the nail with the head of the hammer to get it started, then hit the nail harder, and so forth. Once you understand the steps involved in using a hammer, you can apply your hammer skills any time a set of instructions calls for you to use one, without having to worry about the details. Creating detailed “low-level” descriptions of steps (like how to use a hammer) is very similar to the way that software is built. In this chapter, you learn how to create these types of software groupings.
Irv Kalb

Chapter 5. if, else, and elif Statements

All the code that 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. This 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

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

Prior to this chapter, we 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 a city, or a 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.
Irv Kalb

Chapter 8. Strings

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

Chapter 9. File Input/Output

In every program that 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 that 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 that you generated.
Irv Kalb

Chapter 10. Internet Data

In the previous two chapters, we discussed different ways to get and manipulate strings. This is our third chapter on strings.
Irv Kalb

Chapter 11. Data Structures

Let’s start this chapter with the following definition.
Irv Kalb

Chapter 12. Where to Go from Here

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