复习dive into python

阅读更多
d={'a':'bcd','b':113,'c':['hah','kk']}
del d[2]
d.clear()
d.keys()
d.values()
d.items()
params.values()[n] == params[params.keys()[n]] ,字典无序输出有序
";".join(["%s=%s" % (k, v) for k, v in params.items()])
---------------
li[-1],li[1:3],li[1:-2],li[1:],li[:],li.append("new"),li.insert(2, "new"),
li.extend(["two", "elements"]),len(li) ,li.index("example"),"c" in li--False,
li.remove("z")--只删一个,li.pop()--还返回值,li += ['two'],li = [1, 2] * 3 ,
li = [elem*2 for elem in li],
anystring.split(delimiter, 1)---第二个参数是分割的次数
---------
(x, y, z) = v
(MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY) = range(7)
print range.__doc__
"%s=%s" % (k, v)
-------apihelper.py-----------自省---反射?----可以做个自动提示功能-
def info(object, spacing=10, collapse=1):   
    """Print methods and doc strings.Takes module, class, list, dictionary, or string."""
    methodList = [method for method in dir(object) if callable(getattr(object, method))]
    processFunc = collapse and (lambda s: " ".join(s.split())) or (lambda s: s)
    print "\n".join(["%s %s" %(method.ljust(spacing),processFunc(str(getattr(object, method).__doc__))) for method in methodList])
if __name__ == "__main__":                 
    print info.__doc__

-------------------------type、str、dir----
type(apihelper) == types.ModuleType
callable(string.punctuation),callable(string.join) 
getattr(li, "append")("Moe")

你可能感兴趣的:(Python,C,C++,C#)