Two problems: first, your replacements aren't taking effect, and second, you're not returning anything. You need to do this:
def convert(a):
myStr = "2014년 8월 19일 오후 11:08, 회원님 : 안녕"
myStr = myStr.replace("년 ", a)
myStr = myStr.replace("월 ", a)
myStr = myStr.replace("일 ", a)
return myStr
b = convert(",")
print(b)
replace
does not modify the string, it returns a new string, so if you want to save the result, you need to assign it to a variable. Also, your function will return None
unless you tell it to return something else, which is why you were seeing None.
Also, I moved your string inside the function. If you want to define it outside, you either need to pass it in as an argument, or use global myStr
to make it a global variable (but the first option is better).
I also changed you variable name from str
to myStr
. str
is the name of a builtin type in Python, so it's best not to use that name for your own variable.