Here are examples:
a = '12y'
# ch = ord(a) TypeError: ord() expected a character, but string of length 3 found
ch = chr(ord(a[0])+1)
print(ch) #2
ch = chr(ord(a[2])+1)
print(ch) #z
#给字符串赋值没有太好的方式,切片是有效操作之一
#a[1] = 'x' #TypeError: 'str' object does not support item assignment
a = a[:1]+'x'+a[2:]
print(a) #1xy
#或者变成list
a_list = list(a)
a_list[1] = 'e'
print(''.join(a_list)) #1ey
来源:CSDN
作者:taoqick
链接:https://blog.csdn.net/taoqick/article/details/104108466