An Playful Introduction to Python

XKCD 353: Python


[I wrote 20 short programs in Python yesterday. It was wonderful. Perl, I’m leaving you.]


Python is a programming language designed specifically to make it easy to write clear, readable programs. Flying is often used as a metaphor for freedom and ease, and here Randall shows Cueball literally flying in response to using Python.

A “Hello, World!” program is a very simple program that prints the phrase “Hello, World!”, used in textbooks to illustrate a given programming language. While this sounds simple, it can be nontrivial in some programming languages where you need to explicitly import a library that contains the print function (for instance, in C you need to begin with #include <stdio.h>) or do complicated things with classes and variables (see the Java “Hello, World!” for one example). Python doesn’t need any of that: print "Hello, world!" (or in Python 3.0, print("Hello, world!")) really is all you need to do.

Dynamic typing and significant whitespace are two controversial features of Python, which make some people—like Cueball’s friend—hesitant to use the language.

Dynamic typing means that variables do not have types (like “list of short integers” or “a bunch of letters”); any value of any type can be placed in any variable. Dynamic typing allows for more flexible languages, but it means that certain kinds of errors (like trying to subtract a letter from a number) can’t be caught until a program is run, and some people think this is too dangerous for the tradeoff to be acceptable.

Whitespaces are invisible text characters, like spaces or tabs. In programming, blocks of code controlled by a statement are usually indented under that statement. Most languages require you to use braces ({…}) or special keywords (BEGIN…END) to delimit these blocks; in Python, the indentation itself is the delimiter. Many Python programmers find that this makes code more readable, but many other programmers find it too “magical” and don’t trust it.

Classes, functions and constants in Python are packed into modules. To use a module, you write “import module” at the top of your source file. Python comes with a very powerful standard library of modules to do everything from parsing XML to comparing two sets of files for differences, and new modules can be easily installed from the PyPI repository, which has more than 79,000 more to choose from (as of April 2016). Cueball can fly because he imported the antigravity module. Python still works for Cueball in 482: Height.

In the final panel, Cueball admits that his ability to fly may actually be because he has “sampled everything in the medicine cabinet”, though he’s sure it is the Python anyway. An implication of this is that ingesting everything in the medicine cabinet has given him the feeling of freedom and ease that “flying” represents - or that he is hallucinating himself flying and having a conversation with the other character about it. Here, the metaphor of “feeling like you’re flying” while using Python is transformed back from being literal (Cueball is actually flying) to being metaphorical (Randall feels like he is flying because Python is so easy to use... or because he had too many strange drugs).

Perl, mentioned in the title text, is another programming language with the same target audience as Python, as both are high-level, general-purpose, interpreted, dynamic programming languages. However they strongly oppose each other in their language design:

  • Perl’s philosophy for its syntax is “There’s more than one way to do it”, so each coder can choose his own coding style to do exactly the same thing,
  • Python’s philosophy for its syntax is “There should be one— and preferably only one —obvious way to do it”, so the written code is more consistent.

Since he has discovered Python Randall doesn’t like Perl anymore, probably because its syntax is less consistent.


  • In response to this comic, the Python developers implemented the module antigravity in version 2.7+. When you import it, the default web browser will open this comic. Also, in version 3+, the module contains a geohashing function.
  • As Perl could also be the name of a girl the title text of leaving Perl has double meaning. Also, being with the other program was wonderful. He has not only been unfaithful he is actually leaving!

XKCD 413: New Pet

New Pet


Megan and Cueball create a new pet by putting an EEE PC into a hamster ball, allowing it to roll around.

The Asus Eee PC was one of the first subnotebook computers available on the American market, noted for its small size and coming pre-installed with Linux. With a diagonal size of 11 inches, it would take a big hamster ball to carry it like this.

Omniwheels are wheels with rollers mounted on the edge to allow the wheel to slide sideways. The wheels in the drawing look more like Mecanum wheels, which have rollers mounted at an angle to the edge. Both Omniwheels and Mecanum wheels are used in omni-directional drive systems, like you would use to drive a hamster ball from the inside. A webcam is connected magnetically to the top of the hamster ball, which connects to an rf link to transmit wirelessly to the computer.

TCO is total cost of ownership, which is exactly what it sounds like: the purchase price of something, plus all costs of keeping, operating, and/or maintaining that something. It’s used in accounting to determine something’s true cost-to-value evaluation. In the case of a cat, TCO would primarily consist of food, litter, veterinary care, etc. Refer to trivia for more details. For the device in the comic, there would be a small ongoing cost (occasional recharges for the batteries) after the initial investment.

A Roomba is a self-directed robotic vacuum cleaner made by iRobot.

Python is a programming language popular among geeks running Linux. Among other features, it has a large number of easily installed 3rd-party libraries which make it easy to add features to programs. In this case, Cueball is importing the “soul” library to give the new pet a soul – [STRIKEOUT:obviously] something that a programming language cannot actually do. (citation needed)

This isa reference to XKCD 353 (above).

The title text refers to the One Laptop per Child project spearheaded by Nicholas Negroponte around 2005, with the goal of building an inexpensive, durable sublaptop that could be distributed to children in developing countries to give them an educational edge.


  • According to Pet Education’s list, the TCO for a cat is between 310 and 1169 USD per year.