How to Fix the Python Error: 'builtin_function_or_method' object is not subscriptable

The Python language combines a clean programming syntax that uses formatting as programming logic with a truly incredible scope. The language has a vast ocean of 3rd party libraries. But even the default Python standard library is truly immense when compared to most other programming languages. But this scope does have a downside, especially when combined with Python’s unique formatting rules. It’s often easy to lose track of what and how to call functions and methods. And this often leads to a “builtin_function_or_method’ object is not subscriptable” error message.

A Quick Overview of the Underlying Issue

The Python error might seem a little convoluted at first glance. But the error is essentially stating that we’re making an attempt to access a position within a function or method instead of initializing it. Stating that we’re attempting to subscript a function or method is just a technical way of stating that we’re calling a point within a singular entity rather than the whole. A singular entity that can’t be accessed as a subcomponent of itself. You can essentially think of this as Python’s equivalent to mixing up a noun and verb in English. You can throw a pear. But you can’t pear a throw. Likewise, you can’t access a function or method as if it were a sequence of characters.

A Deeper Look at One of Python’s Most Important Qualities

This might seem like a complicated issue at first. And it’s true that some of the design methodologies behind the language are quite complex. But thankfully, we only really need to understand the surface level of Python’s design in order to see what’s happening with this error.

Python is a much more visually oriented programming language than most of its peers. White space is part of Python’s program logic rather than just a recommendation to keep your source code tidy. Even variations in a type of character can change things around dramatically. And that’s usually the underlying cause of a “builtin_function_or_method’ object is not subscriptable” Python error. People usually aren’t making a mistake through any purposeful intent to split functions in twain. The programmers are instead simply mixing up the syntax used within their code. This issue can be better understood with a simple example.

planets = [‘Mercury’, ‘Venus’, ‘Earth’, ‘Mars’, ‘Jupiter’, ‘Saturn’, ‘Uranus’, ‘Neptune’]
planets.append[‘Pluto’]
print(planets)

Consider a situation where we need to work with a list containing all of the known planets in our solar system. We start out the Python code by creating the list under the variable name “planets”. But what if, at some point, we decided that we also wanted to go against convention and add Pluto to the list of planets? List’s append method should be able to easily take care of the missing planet. Append is a built-in component of Python’s list object and we can call it without any additional import statements. We do so and pass ‘Pluto’ as a parameter. And, finally, we print the resulting list to the screen. Or at least that’s the intent. In reality, we see the “‘builtin_function_or_method’ object is not subscriptable” error.

You might have to really scrutinize the code before you see what the problem is. On line two when we call append we’re using square brackets. But we should be using round brackets. One of the reasons why this error is so prevalent is that we tend to use both types of brackets, constantly, within the same code blocks. It’s very easy to simply overlook which bracket we’re using at any given time. But the two types of brackets have very different meanings.

A square bracket, in Python’s syntax, signifies a position. While circle brackets are used to call specific functionality. Square can be thought of as spatial adjectives while circles are more like a verb. Think of it as a circle representing a ball that you throw. While squares signify a box to throw things into. With that in mind, we can fix the problem quite easily.

How To Fix the Error

On a technical level the problem simply comes down to using the wrong type of bracket. As such, the solution is as simple as changing the square brackets to circles. Try running the following code with that change in effect on line 2.

planets = [‘Mercury’, ‘Venus’, ‘Earth’, ‘Mars’, ‘Jupiter’, ‘Saturn’, ‘Uranus’, ‘Neptune’]
planets.append(‘Pluto’)
print(planets)

You should now see a complete list of the planets, including Pluto, printed to screen. This particular error is a fairly easy mistake to make. But, thankfully, it’s also an easy problem to fix. When in doubt just remember that square brackets are an index operator. The square brackets can almost be thought of as something similar to a book opening to an index. And like the index in a book, an index operator needs to point to a specific numerical point. Whereas circles are a function call. They actively call functionality present in a method or function.

How to Fix the Python Error: 'builtin_function_or_method' object is not subscriptable
Scroll to top