假设分隔符为“ ...”,但它可以是任何字符串。text = 'some string... this part will be removed.'head, sep, tail = text.partition('...')>>> print headsome string如果找不到分隔符,head将包含所有原始字符串。分区功能是在Python 2.5中添加的。分区(...)S.partition(sep)->(head,sep,tail)Searches for the separator sep in S, and returns the part before it,the separator itself, and the part after it. If the separator is notfound, returns S and two empty strings.