小册名称:Python合辑4-130个字符串操作示例
Python比较两个字符串保留一端的差异
def after(s1, s2): index = s1.find(s2) if index != -1 and index + len(s2) < len(s1): return s1[index + len(s2):] else: return Nones1 = "canada"s2 = "can"print(after(s1, s2))
def after(s1, s2):
index = s1.find(s2)
if index != -1 and index + len(s2) < len(s1):
return s1[index + len(s2):]
else:
return None
s1 = "canada"
s2 = "can"
print(after(s1, s2))
Output:
ada