TryBugHunt

Python prints <bound method …> instead of a value

Python prints <bound method …> instead of a value in Python means you used a method without calling it. Without the () at the end, Python gives you the method itself, not the result of running it.

PythonPattern: Logic errors

How do I fix Python prints <bound method …> instead of a value?

When Python prints <bound method Dog.speak of ...> instead of a value, you used the method without calling it. Add the parentheses: dog.speak() runs the method, dog.speak is the method itself. The same mistake makes if user.is_admin: always true, and words = text.split then words[0] fails with 'not subscriptable'.

  1. 1. Look for missing ()Find the method name on that line and check it ends with (), even with no arguments.
  2. 2. Check if conditionsif obj.method: is always true. Write if obj.method(): so the result is tested.
  3. 3. Check before indexing'method' object is not subscriptable means you indexed the method. Call it first: text.split()[0].

What does Python prints <bound method …> instead of a value mean?

dog.speak is the method; dog.speak() runs it. Printing the method shows something like <bound method Dog.speak of <__main__.Dog object at 0x…>>. Using it in an if is worse: a method is always truthy, so the condition is always true, with no error at all.

Why does Python prints <bound method …> instead of a value happen?

1. Forgot the () when calling a method

Without parentheses you get the method object, not what it returns.

Breaks

class Dog:
    def speak(self):
        return "Woof"

print(Dog().speak)
# <bound method Dog.speak of <__main__.Dog object at 0x...>>

Works

print(Dog().speak())   # Woof

2. Checking a method in an if

A method object is always truthy, so this if always runs, even for users who are not admins.

Breaks

class User:
    def __init__(self, role):
        self.role = role
    def is_admin(self):
        return self.role == "admin"

if User("guest").is_admin:
    print("Welcome, admin")   # runs for everyone

Works

if User("guest").is_admin():
    print("Welcome, admin")

3. Indexing a method or built-in instead of its result

Square brackets on the method itself fail with "'method' object is not subscriptable". Call it first, then index the result.

Breaks

words = "a b c".split
print(words[0])
# TypeError: 'builtin_function_or_method' object is not subscriptable

Works

words = "a b c".split()
print(words[0])   # a

How to find it in your own code

Search the line for a method name that is not followed by (). If you see <bound method …> or "method object is not subscriptable", add the parentheses. For if checks, make sure you compare the result of the call, not the method.

Practise logic errors

None of the challenges raises this exact error yet. These practise the same kind of bug.

Still not sure why yours breaks?

Paste it into the visualizer and watch it run line by line, with every variable at every step. Free, and it runs in your browser.

Related error guides

View all logic errors →