本文主要是介绍python str ord chr 字符串赋值 trailing comma 尾巴逗号,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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) #2ch = 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)) #1eya = [[]]
# a[-1][1:] = 3 #肯定会崩
a[-1][1:] = 3, #相当于a[-1].append(3)
print(a)
这篇关于python str ord chr 字符串赋值 trailing comma 尾巴逗号的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!