Entries from 2013-11-01 to 1 month

Python intensive dictionary introduction

Constructors d = {} # dict literal notation d = dict() d = {'one': 1, 'two': 2} # dict literal d = dict([('one', 1), ('two', 2)]) # list of tuples d = dict(one=1, two=2) # keyword arguments Dictionary from key value pair >>> keys = "one tw…

Python str.format

str.format Pro: flexible format Con: this is not common interface for programmer who is familiar with other language Eg >>> "{0} is good. {1} is better! {2} is awesomeXDDDD".format('foo', 'bar', 'baz') 'foo is good. bar is better! baz is a…

Magic method

http://www.rafekettler.com/magicmethods.html

for else

for ... else statement else is executed only for is finished all range. Pro: Flag can be omitted.Eg1 for i in range(1, 10): print i if i == 11: break else: print "do else" out put >>> ================================ RESTART ==============…