如果要避免在打印输出中包含点,可以使用字符串替换方法。以下是一个示例代码:
def remove_dots(text):
# 使用replace()方法将点替换为空字符串
new_text = text.replace(".", "")
return new_text
# 示例用法
text = "Hello World."
new_text = remove_dots(text)
print(new_text) # 输出:Hello World
在上述示例中,我们定义了一个remove_dots
函数,它接受一个字符串参数text
。然后使用replace()
方法将字符串中的点替换为空字符串,并将替换后的结果返回。在示例用法中,我们传入了一个包含点的字符串"Hello World."
,然后打印输出替换后的结果Hello World
,不再包含点。