Return a list of the words in the string, using sep as the delimiter
string. If maxsplit is given, at most maxsplit splits are done (thus,
the list will have at most maxsplit+1 elements). If maxsplit is not
specified or -1, then there is no limit on the number of splits (all
possible splits are made).
您可以使用标准字符串方法
partition
,该方法搜索给定的分隔符并返回一个3元组,由前面的字符串部分、分隔符本身和后面的部分组成。你可以用
a,b = split(' ', 1)
。第二个参数
1
是要执行的最大拆分数。有关字符串分割函数的详细信息,请参见^{} in the manual 。
从Python docs
相关问题 更多 >
编程相关推荐