字符串不转义

    print r"output message\n\r"

字母和对应的数字相互转换

    print ord('A')
    print chr(65)

unicode编码支持

    print u'中文'

字符串格式化

    print "%s have $%d" % ("you", 100)

集合

    list, tuple, dict, set

空函数

    def nop():
        pass        

类型检查

    if not isinstance(x, (int, float)):
            raise TypeError('bad operand type')

切片

L 是一个list或者tuple

    L[1:3], L[-2:], L[:]

列表生成

    [x * x for x in range(1, 11) if x % 2 == 0]

生成器

    >>> def odd():
    ...     print 'step 1'
    ...     yield 1
    ...     print 'step 2'
    ...     yield 3
    ...     print 'step 3'
    ...     yield 5        
    >>> o = odd()
    >>> o.next()
    step 1
    1
    >>> o.next()
    step 2
    3
    >>> o.next()
    step 3
    5

偏函数

    import functools
    int2 = functools.partial(int, base=2)

文件读取

    def read_file(path):
        s = set([])
        f = open(path, 'r')
        for line in f.readlines():
            s.add(line.strip())
        return s


        /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/mpl-data/fonts/ttf

行列操作

http://blog.csdn.net/y12345678904/article/details/72757912

matplotlib 图形中文乱码

查看 matplotlib 所在目录:print(matplotlib.matplotlib_fname()) 其他:http://www.jianshu.com/p/02956fb520a7