It has been months since i wrote something here.During the intervening time i happened to see ‘Python Cookbook’ and i am publishing my notes and examples here,hoping that someone like me will find them useful.
In python we don’t have to use temporary variables to swap variable values.Python’s automatic tuple packing and unpacking make this a snap:
a, b, c = b, c, a
When the keys are identifiers, a cleaner way is

We need to obtain a value from a dictionary, without having to handle an exception if the key you
seek is not in the dictionary.We usually use like
let d = {‘a’:1, ‘b’:2 ,’c’:3} is the dictionary then
if d.has_key('a'):
print d['a']
else:
print 'not found'
However, there is a much simpler syntax:
print d.get('a', 'not found')

