Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - Convert Underscore to Fullstop

Convert String '321_1' to '321.1'.

I would like to create a method to convert the underscore to full stop. i used split but it cant work .. Anyone can help me? or must i use while loop

Convert underscore to fullstop

def Convert_toFullStop(text):

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

2 Answers

use the replace() function?

newtext = text.replace('_','.')
like image 97
HongboZhu Avatar answered May 05 '26 15:05

HongboZhu


I would do

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

and leave the print to the caller.

like image 40
glglgl Avatar answered May 05 '26 16:05

glglgl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!