Skip to main content
 首页 » 编程设计

Python之将下划线转换为句号

2025年05月04日12TianFang

将字符串 '321_1' 转换为 '321.1'。

我想创建一个将下划线转换为句号的方法。我用过 split 但它不能工作.. 任何人都可以帮助我吗?或者我必须使用 while 循环

将下划线转换为句号

def Convert_toFullStop(text): 
 
    x1 = "" 
    words = text.split() 
    if words in ("_"): 
        words = "." 
    print words 

请您参考如下方法:

使用replace()功能?

newtext = text.replace('_','.')