python 实现字符串的切片功能
'''string切片''' def string_split(stringone,split): m = [] if type(split)!=str: return False if split not in stringone : m.append(stringone) return m if type(stringone)!=str: return False if not split: m.append(stringone) return m else: h=0 l=0 for i in range(len(stringone)): if stringone[i]==split: if i==0 and h==0: n = (stringone[0]) elif h>0: n=stringone[l:i] else: n=stringone[0:i] if i==len(stringone)-1: c = stringone[len(stringone)-1] elif h>0 : c=stringone[-1] else: c='' if len(n)!=0 : m.append(n) if len(c)!=0: m.append(c) i += 1 h += 1 l= i else: i+=1 return m print(string_split('12,22,11',split='1,'))
出 处:https://www.cnblogs.com/leiziv5/p/8631433.html