2024-10-03 00:23:12 发布
网友
将字符串'321_1'转换为'321.1'。你知道吗
'321_1'
'321.1'
我想创建一个方法来将下划线转换为句号。我用分裂法,但它不能工作。。有人能帮我吗?还是必须使用while循环
将下划线转换为句号
def Convert_toFullStop(text): x1 = "" words = text.split() if words in ("_"): words = "." print words
最好的方法是使用上面答案中建议的replace()方法。你知道吗
replace()
但是如果你真的想用split():
split()
words = text.split("_") print ".".join(words)
默认情况下,split()方法按空格字符分割。你知道吗
使用replace()函数?你知道吗
newtext = text.replace('_','.')
我会的
def Convert_toFullStop(text): return text.replace('_', '.')
把print留给调用者。你知道吗
print
最好的方法是使用上面答案中建议的
replace()
方法。你知道吗但是如果你真的想用
split()
:默认情况下,
split()
方法按空格字符分割。你知道吗使用replace()函数?你知道吗
我会的
把
print
留给调用者。你知道吗相关问题 更多 >
编程相关推荐