Python Easter Eggs

This is something I discovered incidentally... On the Python interpreter try out these commands C:\Python27\pylibrary\PyLibrary>python ActivePython 2.7.2.5 (ActiveState Software Inc.) based on Python 2.7.2 (default, Jun 24 2011, 12:21:10) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import this  --> Prints out Zen of Python The … Continue reading Python Easter Eggs

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

Performance for testing memberships: list vs tuples vs sets

Sets in Python are often used for two purposes: 1. Removing the duplicate entries in a collection 2. For membership testing. By membership, here we mean to find existence of element in a collection The focus of this post is to evaluate performance of list, tuple and set data structures with respect to each other … Continue reading Performance for testing memberships: list vs tuples vs sets

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