Python编程常用技巧,你全知道么?( 五 )

difflib.get_close_matches('appel' ['ape' 'apple' 'peach' 'puppy'
n=2)

# 返回['apple' 'ape'

difflib.get_close_matches会查找相似度最匹配的字串 。 本例中 , 第一个参数与第二个参数匹配 。 提供可选参数n , 该参数指定要返回的最大匹配数 , 以及参数cutoff(默认值为0.6)设置为thr确定匹配字符串的分数 。

多行字符串

Python中可以使用反斜杠:

In [20
: multistr = \" select * from test \\

...: where id < 5\"

In [21
: multistr

Out[21
: ' select * from test where id < 5'

还可以使用三引号

In [23
: multistr =\"\"\"select * from test

...: where id < 5\"\"\"

推荐阅读