记录一次笔试题:【去除str = [“aababbc”, “badabcab”] 中的“ab”,语言不限】
python
def data_action(data_str, str):
if str in data_str:
data_str = data_str.replace(str, '')
return data_action(data_str, str)
return data_str
data_action(data_str='aabbcdbaaabc', str='ab')
replace 的用法
str.replace(old,new,max)
第一个参数是要进行更换的旧字符,第二个参数是新的子串,将取代旧的子串,第三个参数是替换多少次,默认是全部