Jul 6, 2011

Notes

'a' + 'b' # slow
'%s%s' % ('a', 'b') # faster

>> 'an' in 'Django'
True

>> ['a', 'b', 'c'] * 2
['a', 'b', 'c', 'a', 'b', 'c']

>> [x for x in range(10) if x % 2 == 0]
[0, 2, 4, 6, 8]

{'a' : 123, 'b' : '345'}['c'] # KeyError

{'a' : 123, 'b' : '345'}.get('c', 'N/A') # {'a' : 123, 'b' : '345', 'c' : 'N/A'}
'N/A'

No comments: