0

I am doing leetcode problems on basics of python. I am getting error code as below on leetcode.

TypeError: reverseString() takes 1 positional argument but 2 were given ret = Solution().reverseString(param_1) Line 28 in _driver (Solution.py) _driver()
 class Solution:
        def reverseString(s: List[str]) -> None:
            if len(s)==0:
                return s
            else:
                return Solution.reverseString(s[1:])+s[0]
Random Davis
  • 6,662
  • 4
  • 14
  • 24
Selva
  • 43
  • 3
  • Does this answer your question? [TypeError: method() takes 1 positional argument but 2 were given](https://stackoverflow.com/questions/23944657/typeerror-method-takes-1-positional-argument-but-2-were-given) – Random Davis Jan 05 '21 at 17:11

2 Answers2

0

reverseString is a class method but you didn't define a self parameter as the first argument. You should either put that in as the first argument, or use the @staticmethod decorator. This is explained much better in this existing post: TypeError: method() takes 1 positional argument but 2 were given

Random Davis
  • 6,662
  • 4
  • 14
  • 24
0

you need to provide one argument instead of two.

  • I don't think this answer really explains why two arguments are being passed when their code (`Solution().reverseString(param_1)`) only sends one. The reason Python thinks two arguments are being sent is because it's a class method, so Python is automatically sending `self` as the first argument. – Random Davis Jan 05 '21 at 17:13