关于#python#的问题:检查字符串“Life is short.I use python”中是否包含字符串“python”,若包含则替换为“python”后输出新字符串,否则输出原字符串
问题描述:
编写程序,检查字符串“Life is short.I use python”中是否包含字符串“python”,若包含则替换为“python”后输出新字符串,否则输出原字符串
答
a='Life is short.I use python'
if 'python' in a:
print(a.replace('python','java'))
else:
print(a)