Python-将下划线转换为Fullstop

Python-将下划线转换为Fullstop,python,coding-style,Python,Coding Style,将字符串'321_1'转换为'321.1' 我想创建一个方法来将下划线转换为句号。我用的是split,但它不能用。。有人能帮我吗?还是必须使用while循环 将下划线转换为句号 def Convert_toFullStop(text): x1 = "" words = text.split() if words in ("_"): words = "." print words 使用该功能 newtext = text.replace('_',

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

我想创建一个方法来将下划线转换为句号。我用的是split,但它不能用。。有人能帮我吗?还是必须使用while循环

将下划线转换为句号

def Convert_toFullStop(text):

    x1 = ""
    words = text.split()
    if words in ("_"):
        words = "."
    print words
使用该功能

newtext = text.replace('_','.')
使用该功能

newtext = text.replace('_','.')
我愿意

def Convert_toFullStop(text):
    return text.replace('_', '.')
然后把打印的
留给打电话的人。

我会的

def Convert_toFullStop(text):
    return text.replace('_', '.')

并将
打印
留给调用者。

最好按照上面答案中的建议使用
replace()
方法

但是如果您确实想使用
split()


默认情况下,
split()

但是如果您确实想使用
split()


默认情况下,
split()。请在下次提问之前尝试:-)@user2837162不完全是函数,它是字符串对象的方法。python类似于口语。请在下次询问之前尝试:-)@user2837162不完全是函数,它是字符串对象的方法。