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