【发布时间】:2018-08-20 09:26:05
【问题描述】:
目标:找出以句首开头的数字,并将原位数字更改为等于原数字加10%。
msg_orginal = """Hello, I am new here.
2,431 other coders are new here too.
Imagine if 2.5 were not new here?
2,428.5 would then be new."""
我正在寻找的输出如下:
msg_revised = """Hello, I am new here.
2,674.1 other coders are new here too.
Imagine if 2.5 were not new here?
2,671.35 would then be new."""
请注意三个句子中的两个如何改变了数值,但一个没有。
编辑: 请记住,相同的数字可能会在字符串中出现多次。新句子是在句号(如句号、感叹号、问号)之后或换行符之后出现的句子。
【问题讨论】:
-
@jdehesa 实际上,使用正则表达式可能更容易
-
@Student 同一个数字有可能出现两次吗?
-
@DeepSpace 是的。我已对上述内容进行了澄清。感谢您提出问题。
-
新句子是句号之后的句子(或问号等)还是换行符之后的句子?
标签: python string python-3.x replace