有没有办法转换字符串-';光比声音传播得快';进入';光比声音传播得快';用Python

有没有办法转换字符串-';光比声音传播得快';进入';光比声音传播得快';用Python,python,string,indexing,slice,Python,String,Indexing,Slice,我想将Python中的光速比声音快转换为光速比声音快 这是我试过的 s = "Light travels faster than sound.This is why some people appear bright until you hear them speak" s.replace('Light', 'LIGHT') s.replace('sound', 'SOUND') print(s) 字符串是不可变的replace返回一个新字符串,谢谢。我会记住这件事的

我想将Python中的
光速比声音快
转换为
光速比声音快

这是我试过的

s = "Light travels faster than sound.This is why some people appear bright until you hear them speak"
s.replace('Light', 'LIGHT')
s.replace('sound', 'SOUND')
print(s)

字符串是不可变的
replace
返回一个新字符串,谢谢。我会记住这件事的