W3docs

TypeError: method() takes 1 positional argument but 2 were given

This error message is indicating that a method or function called "method" is expecting one argument, but it was called with two arguments.

This error message is indicating that a method or function called "method" is expecting one argument, but it was called with two arguments. Here is an example of how this error might occur:

TypeError in Python

class MyClass:
    def method(self, arg1):
        print(arg1)

obj = MyClass()
obj.method("hello", "world")  # raises TypeError

In this example, the method is defined to take one argument arg1 but when we are calling the method with two arguments "hello" and "world" So, it raises TypeError.

It can be fixed by only passing one argument to the method:

TypeError fixed in Python

obj.method("hello")  # prints "hello"

Or by modifying the method definition to accept two arguments:

TypeError occurance

class MyClass:
    def method(self, arg1, arg2):
        print(arg1, arg2)

obj = MyClass()
obj.method("hello", "world")  # prints "hello world"