Tag Archives: Learning Python

Learning Python In A Flash…

… card.

Python Flash Cards: Syntax, Concepts, and Examples is a new book-not-a-book that helps people who are staring out learning the Python programming language.

First, lets get one thing straight about Phython. If you (or, maybe, your kid) is going to learn to code, you’ve got to learn Python. It isn’t the only coding language out there, and depending on what you do with coding, Python might be something you do all the time or almost never. But it is a good bet that the arbitrary future coder will be coding in Python in the future.

Python is both simple and complex, easy and hard. I think it is probably easier for people who have never previously coded to learn than for old timers who cut their teeth on structured languages. Python actually is structured, but it is also object oriented. If you don’t know the difference between the two, don’t worry. Suffice it to say that the following works:

This is using a command interpreter, demonstrating that Python is sort of like a command line language if you want it to be. I entered Python statements and got instant results. That is not how Python is usually run, but it can be helpful.

Notice that I created a “list” which is an object that includes a list of things. I cleverly made the list, in its original form, a sentence of sorts. I then printed it so you could see that the list indeed has stuff in it. What I did there could be done in a similar form in virtually any language, though the concept of a “list” in Python (as opposed to the very similar “array” or “matrix” in other languages) is much more powerful than demonstrated here.

Then, I did the object-oriented thing. I called up the list (“aList”) but with a dot followed by a thing that made that list change. It became sorted. I then printed it.

Anyway, enough messing around. Python is a great and powerful Oz of a language, and it is very widely used, which means that there are a LOT of powerful libraries that can be drawn on to do a lot of things.

If you, or your kid, plays around with a Raspberry Pi, then you’ll want to learn Python because that is the handiest way to program it.

So, back to the Python Flash Cards. There are helpful and just plain fun. As you learn concepts, you can go through the cards and use them exactly like flash cards (because they are actual flash cards) to both review and backfill gaps in your knowledge.

The topics on the cards range from “what is a string” to how to loop through lists (yes, you can loop through a list) to how to define classes and methods (that’s object-oriented stuff, where you make your own object oriented mojo like the “sort” thingie we used above).

The author is Eric Matthes, a high school science and math teacher in Alaska. He teaches introductory programming classes. He is the author of the previously reviewed and highly recommended Python Crash Course: A Hands-On, Project-Based Introduction to Programming, which goes nicely with the flash cards.

The flash cards are not available yet but will be out in a few days. You can pre-order. They will come in time for the holidays, and they are, in fact, a great holiday gift for your 11 year old future programmer.

How to learn Python programming

Your objective is to learn Python programming. Everybody has to learn Python.

You are looking for a book that will make that easier for you. One possibility, one that I’ll recommend for most people in this situation, is Python Crash Course: A Hands-On, Project-Based Introduction to Programming.

To cut to the chase, there are two reasons I recommend this book. First, the specific programming projects used in the book are a good match for most people, because they are bare bones (but highly developed) exemplars that are fairly adaptable and together cover a wide range of applications and use requirements. Second, the book is well written and organized, the first part very serviceable as a reference book, covers both Python 2 and 3 but focuses on and encourages you to learn 3 (which you should) etc.

Let me go back to that first reason and expand a bit.

Why do you want to learn Python, why do you want to program stuff?

You need to automate or otherwise develop an interactive project. You need to manipulate data live, interact with the computer, etc. You have some data in a text file (or some other form) and you need to access it and turn it into derived numbers, or pictures, graphics, etc. You want to generate web output. Perhaps there is some web scraping in there. Maybe you are doing all this together.

The book begins with eleven chapters on how Python works, and is fairly detailed. If you work through this in detail, and actgually do the recommended exercises, you’ll be a python programmer before you hit Chapter 11.

The second part includes three fairly well developed projects. One is an interactive game that is pretty sophisticated (for a scripting language an not using a GUI). The second uses some of the more powerful mathematical and graphical libraries in Python to manipulate, graph, plot, etc. data. This section also covers working with API’s including Git. This is probably the chapter you’ll come back to the most.

The third project leads you through developing a web application using Django.

A classic use of this book is that you are a scientists who uses R (r-cran) and you suddenly realize that more development of tools is happening in Python than in R. Switching from R to Python is hard to do emotionally, but easy from a programming perspective, because Python is a better programming language. You don’t really want to leave R, but you know that it is time to branch out, and at least, see what you can do with Python. This crash course does not give you the full range of knowledge to switch you from sophisticated use of R to equivalent use of Python, but if you can’t currently program in Python, do this, then do that using more sophisticated resources.

It has been interesting to see, over the last few years, No Starch Press, which produces this book, growing and producing future classics that should be along side the more traditional O’Reilly Press programming books. Python Crash Course: A Hands-On, Project-Based Introduction to Programming is one of those books, equal to or replacing something like Learning Python, 5th Edition, but at close to half the price.

Python is easy to use and learn, yet it is also very powerful. Much of the power comes from the powerful libraries that exist, which can be imported and used for a wide range of things. Python itself is a very simple implementation of an interpreted language, with a simple command line interface. Because of these two things, the actual installation and running of Python is very easy and sometimes very difficult at the same time. Here’s the thing. As a single user who may do some complex stuff, which would describe you if you are like me, you might want a pretty fancy development environment and lots of libraries and stuff. But at the same time, you really don’t want complex virtual environments and collaboration tools. The thing is, as the various free or paid add ons or resources you can get to enhance Python’s power get more complicated, they assume that you are moving from a hobbyist or student to a corporate environment with multiple collaborators and the need to keep projects separate more than you really want. At some point, someone will tell you, “Oh, if you want to do that, just install ______” where the blank is the name of a snake or something. You go in stall it, and find out you have to take a class to know what the first button to press is.

So, that is a complaint I have about the Python world. This book does come with a web site that has on it current and important information, updated, on how to handle some of these problems with installing and configuring your programming environment, using a thing called “pip” which helps you install libraries and stuff, and how to get matplotlib and some other stuff running without having to take that class.

You will also find source code used in the book and some other cool resources on that page.

Following is the top level TOC and here is a PDF file of the full TOC.

Table of Contents

PART I: Basics

Chapter 1: Getting Started
Chapter 2: Variables and Simple Data Types
Chapter 3: Introducing Lists
Chapter 4: Working with Lists
Chapter 5: if Statements
Chapter 6: Dictionaries
Chapter 7: User Input and while Loops
Chapter 8: Functions
Chapter 9: Classes
Chapter 10: Files and Exceptions
Chapter 11: Testing Your Code

PART II: Projects

Project 1: Alien Invasion
Chapter 12: A Ship that Fires Bullets
Chapter 13: Aliens!
Chapter 14: Scoring

Project 2: Data Visualization
Chapter 15: Generating Data
Chapter 16: Downloading Data
Chapter 17: Working with APIs

Project 3: Web Applications
Chapter 18: Getting Started with Django
Chapter 19: User Accounts
Chapter 20: Styling and Deploying an App


Appendix A: Installing Python
Appendix B: Text Editors
Appendix C: Getting Help
Appendix D: Using Git for Version Control

View the detailed Table of Contents (PDF)
View the Index (PDF)