Skip to content

Python One Liner for Fibonacci Series

fibonacci = lambda x: x if x<=1 else fibonacci(x-1)+fibonacci(x-2)

Output: 610

Explanation of code:

This code includes lambda function it basically means anonymous function. We create a function with variable x. If x greater then 1 we sum the function x-1 and x-2 so it repeat itself till 1. It is recursive function.

Published inPython

Be First to Comment

Leave a Reply

%d bloggers like this: