str = ‘ AAA|+aaa |BBB|+ccc DDD|ddd+EEE ‘ print str,‘len = ‘,len(str) print ‘\n‘ x = raw_input(‘plz input the separator:‘) a=b=n=0 while a <= len(str): while str[a] == x : a= a + 1 n = a if a == len(str): break if a == len(str): break while str[a] != x : a = a + 1 m = a if a == len(str): break print ‘n=‘,n,‘m=‘,m,str[n:m] if a == len(str): break
先写在这里,每个while 都用了break才能退出,不然运行会因为超过index数报错。
时间: 2024-09-30 20:55:23