2024-04-25 09:34:04 发布
网友
这只是我问题的一个例子:
string = "This is just a random sentence" print(string)
我如何在is和just之间分割句子,以便在以后放入变量
is
just
string = "This is just a random sentence" splits = string.split('just') variable = 'alex' string = x[0]+variable+' just'+x[1] print(string)
输出:
This is alex just a random sentence
它需要是句子特有的,或者是特定的长度
沿着您可以轻松完成的长度路线:
x = "elephant" string[:8] + x + string[7:]
如果你在空间上拆分字符串,你必须在以后重新组装整个东西
你想做这样的事吗
string = "This is just a random sentence" x = "INSERT" split1 = string[:8] split2 = string[8:] newString = split1 + x + split2 print(split1) print(split2) print(newString)
输出:
它需要是句子特有的,或者是特定的长度
沿着您可以轻松完成的长度路线:
如果你在空间上拆分字符串,你必须在以后重新组装整个东西
你想做这样的事吗
相关问题 更多 >
编程相关推荐