In [132]: split_str = re.compile(r'[{} ]+'.format(string.punctuation))
In [133]: split_str.split("You can do it with one variable you don't have to use multiple variable which can cause confusion. Also code will be much cleaner. You can do it in one line also.")
Out[133]:
['You',
'can',
'do',
'it',
.....
'in',
'one',split_string =
'line',
'also',
'']
伟大的python带来了巨大的责任:不要滥用这个特性!
在PEP 8中编码的规范最大行长度是80个字符, 分割方法链的标准方法是从一个点开始新行:
你可以用一个变量来做,你不必用多个变量,这会引起混乱。代码也会更干净。你也可以一行一行的。
你也可以一行一行的
对于正则表达式,它甚至更干净
相关问题 更多 >
编程相关推荐