On 9/27/19 7:54 AM, ast wrote:
Hello

Is it feasible to define a recursive method in a class ?
(I don't need it, it's just a trial)

Here are failing codes:


class Test:
      def fib(self, n):
          if n < 2: return n
          return fib(self, n-2) + fib(self, n-1)

    return self.fib(n - 2) + self.fib(n - 1)

(1) This is a horribly ineffective way to compute Fibonacci
numbers, but that's not immediately relevant.

(2) Recursive instance methods only make sense when there's
some sort of state being maintained, which in this case there
is not.  But that's also not immediately relevant.
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to