After learning so much about development in Python, I thought this article would be interesting for readers and to myself... This is about 5 different ways of calculating Fibonacci numbers in Python [sourcecode language="python"] ## Example 1: Using looping technique def fib(n): a,b = 1,1 for i in range(n-1): a,b = b,a+b return a print … Continue reading 5 Ways of Fibonacci in Python
Tag: language python
Overloading in Python
Some say Python doesn’t allow overloading of methods or constructors. Well, they are right in some way! A coding example below, [sourcecode language="python"] def add(a,b): return a+b def add(a,b,c): return a+b+c print add(4,5) [/sourcecode] If you try to run the above piece of code, you get an error stating, “TypeError: add() takes exactly 3 arguments … Continue reading Overloading in Python
Mystery with remove and pop in Python lists
Thanks Vishal for his inputs on this.. According to python docs list.remove(x)Remove the first item from the list whose value is x. It is an error if there is no such item.list.pop([i])Remove the item at the given position in the list, and return it. If no index is specified, a.pop() removes and returns the last … Continue reading Mystery with remove and pop in Python lists