5 Ways of Fibonacci in Python

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

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

Python Decorators

Let's start with something simple..What is a decorator? According to python.org, "A decorator is the name used for a software design pattern. Decorators dynamically alter the functionality of a function, method, or class without having to directly use subclasses or change the source code of the function being decorated" A classic example tat I can … Continue reading Python Decorators

Euler project in Python

Solution to Euler project in Python Problem 1-10 [sourcecode language="python"] ## For class Helper see below helperObj = Helper() def problem1(self): ''' Add all the natural numbers below one thousand that are multiples of 3 or 5. ''' numbers = range(0,1000) return reduce(lambda x,y: x+y, filter(lambda(x):x%3==0 or x%5==0, numbers)) def problem2(self): ''' By considering the … Continue reading Euler project in Python