Python 字符串修改:替换指定位置的字符
以下是使用 Python 编写的解决方案:
def modifyString(string, char, position):
if position < len(string):
string = string[:position] + char + string[position+1:]
return string
# 输入字符串
input_string = input('请输入字符串:')
# 输入修改的字符
char = input('请输入要修改的字符:')
# 输入修改的位置
position = int(input('请输入要修改的位置:'))
# 调用函数进行修改
modified_string = modifyString(input_string, char, position)
# 输出结果
print('修改后的结果:', modified_string)
希望对你有所帮助!
原文地址: https://www.cveoy.top/t/topic/SUj 著作权归作者所有。请勿转载和采集!