# The Invent with Python Blog

Writings from the author of Automate the Boring Stuff.

# 22 Examples of Recursive Functions in Python

Mon 04 October 2021    Al Sweigart

Here are 22 actual, runnable Python code for several recursive functions, written in a style to be understandable by beginners and produce debuggable output.

# What is a Python Generator? (Implementing Your Own range() Function)

Fri 24 September 2021    Al Sweigart

Generators in Python (also called generator functions) are used to create a series of values one at a time. Let's learn how they work by re-creating the built-in `range()` function.

# Recursion Is Not A Superpower: An Iterative Ackermann

Sun 05 September 2021    Al Sweigart

This post has the Python code for the infamously recursive Ackermann function, but without using recursion.

# Algorithmic Art with the BitFieldDraw Module

Mon 02 August 2021    Al Sweigart

I created the `bitfielddraw` Python module so that you could turn math formulas into .png image files.

# Combinations and Permutations in Python with itertools

Sat 03 July 2021    Al Sweigart

Explores the difference between combinations and permutations, and why you don't need to write your own Python code for them because the built-in `itertools` module already exists. Includes working code examples.

# Al Sweigart's PyTennessee 2020 Opening Keynote

Sun 07 March 2021    Al Sweigart

In March 2020, just before the lockdowns would begin, I gave the opening keynote at PyTennessee 2020. Unfortunately, it wasn't recorded. But I still have the script I used and so I re-recorded the talk. I've posted it to my YouTube channel.

# Text Recognition in Python with pytesseract

Mon 11 January 2021    Al Sweigart

Extracting text as string values from images is called optical character recognition (OCR) or simply text recognition. This blog post tells you how to run the Tesseract OCR engine from Python. Includes working code examples.

# A Quick Pip Guide: How to Install Python Modules

Mon 11 January 2021    Al Sweigart

This tutorial teaches you about Pip, a package manager that installs third-party packages for Python.

# Type Hints for Busy Python Programmers

Sun 24 November 2019    Al Sweigart

A quick guide to using type hints in Python.

# Python Error Messages: Gotta Catch Em All

Thu 15 August 2019    Al Sweigart

To make errors less intimidating, I've created a "Gotta Catch 'em All" worksheet that lists several common Python error messages. Instead of trying to avoid errors, beginners can try to hunt and collect them all.

# Pythonic Ways to Use Dictionaries

Wed 05 June 2019    Al Sweigart

Python dictionaries are a useful part of the language. In addition to having the ability to store keys and values, you can also use dictionary methods to manipulate those values, and you can use dictionaries to write more concise code.

# Hashable Objects Must Be Immutable

Fri 01 February 2019    Al Sweigart

A recent post to Reddit sparked some comments, so I wanted to clarify: In Python, hashable objects must be immutable and mutable objects cannot be hashable. (With one exception.)

# A Curriculum for Python Packaging

Mon 22 October 2018    Al Sweigart

Python's packaging ecosystem contains multitudes. It can be intimidating for new Python developers to try to crack into, especially given the rapid evolution of Python packaging. Writing a *helloworld.py* file and running it on your computer is simple, but getting it to run on someone else's computer (and doing this the "right" way) involves a tangle of terms, tools, and techniques. What are wheel files? What is distutils? Do I use distutils or easy_install or pip?

To get to the bottom of this myself, I've compiled a curriculum of PyCon talks, online documentation, and my own personal notes to finally get a complete handle on Python packaging.

# Writing Bots to Play Zombie Dice

Wed 17 October 2018    Al Sweigart

Programming games are a games genre where instead of playing the game directly, players write bot programs to play the game autonomously. I've created a Zombie Dice simulator, allowing programmers to practice their skills while having fun making game-playing AIs. Zombie Dice bots can be simple or incredibly complex, and are great for a class exercise or an individual programming challenge.

# The Zen of Python, Explained

Fri 17 August 2018    Al Sweigart

The Zen of Python by Tim Peters are 20 guidelines for the design of the Python language. Your Python code doesn’t necessarily have to follow these guidelines, but they’re good to keep in mind. The Zen of Python is an Easter egg, or hidden joke, that appears if you run `import this`.

# Python's Fake Increment and Decrement Operators

Mon 21 May 2018    Al Sweigart

In Python, you can increase the value of a variable by `1` or reduce it by `1` using the augmented assignment operators. The code `spam += 1` and `spam -= 1` increments and decrements the numeric values in `spam` by `1`, respectively.

Other languages such as C++ and Java have the `++` and `--` operators for incrementing and decrementing variables. (The name of C++ itself reflects this; the name is a tongue-in-cheek joke that indicates it's an enhanced form of the C language.) Code in C++ and Java could have `++spam` or `spam++`. Python wisely doesn't include these operators; they are notoriously susceptible to subtle bugs.

# Python Tuples are Immutable, Except When They're Mutable

Mon 05 February 2018    Al Sweigart

Before we can get a nuanced answer to "Are tuples mutable or immutable?", we need some background information.

# Translate Your Python 3 Program with the gettext Module

Sat 20 December 2014    Al Sweigart

You've written a Python 3 program and want to make it available in other languages. You could duplicate the entire code-base, then go painstakingly through each .py file and replace any text strings you find. Fortunately, Python provides a solution with the `gettext` module.