Recursive method in class

Rhodri James rhodri at kynesim.co.uk
Fri Sep 27 08:29:40 EDT 2019


On 27/09/2019 12:54, 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)

Try self.fib(...) instead of fib(self, ...) both times.

-- 
Rhodri James *-* Kynesim Ltd



More information about the Python-list mailing list