Python 3.X 在循环中更改字符串元素的值
📁 python
如何在循环中更改字符串中符号的值?代码:
def getDateTimePostfix(): import datetime; dtValue = datetime.datetime.now(); retValue = str(dtValue); for sym in retValue: if sym == ':': sym = '.' return retValue; 我尝试调整日期,去掉":",但无法更改单个字符。
或者用这种循环更好?
i = 0; for item in retValue: if retValue[i] == ':': retValue[i] = '.'