python 字符串及其修改过程

编程实现将“ hello,it's me. Can you help me?” 变成“Hello,it's me. Can you help me? Ok!"(PS:开头有空格)

根据题意,需要用strip()函数去掉字符串前后空格,结合字符串其他处理函数一行即可实现。

s=" hello,it's me. Can you help me?"
print(s.strip().capitalize(),'Ok!')

如果回答对你有帮助,请点击我回答的右上方采纳按钮,给予采纳一下

你题目的解答代码如下:(如有帮助,望采纳!谢谢! 点击我这个回答右上方的【采纳】按钮)

s = " hello,it's me. Can you help me?"
s = s.lstrip()  #去掉开头空格
s = s[0].upper() + s[1:] + ' Ok!'
print(s)

img

a="hello,it's me. Can you helpme?"
b=a.capitalize()+' OK!'
print(b)

a = "hello,it's me. Can you helpme?"
b = "helpme? Ok!"
c = a.capitalize().replace('helpme?', b)
print(c)