tips on writing beautiful code in python – part 1

I’ve been programming in Python for over 7 years now and I must say its the most beautiful language I have ever worked with. They say “beauty lies in the eyes of the beholder”, but when it comes to Python, the language itself is designed to look beautiful. Ok, maybe I am a bit biased !!

The following tips are heavily influenced by the various talks I watched, by Raymond Hettinger, the co-author of Python (who I admire) and a few of my own experiences with Python. Since this is a list of things I collected over the years, I am not able to attribute these to the appropriate authors, but please accept my sincere thanks.

# tuple unpacking

When you want to do something like swapping the values of two variables a, b

temp = a
a = b
b = temp

a better (and safer) way of doing this is by using tuples to unpack.

(a, b) = (b, a)

Continue reading “tips on writing beautiful code in python – part 1”