str_1 = "lllfhafFHFHKJLalokokljasdlll"
str_2 = ('a','s','d')
str_3 = '-'
print("字符串的长度是:"+str(len(str_1)))
print("56对应的ASCII码是:"+chr(56))
print("将字符串中的小写转为大写:"+str.upper(str_1))
print("将字符串中的大写转为小写:"+str.lower(str_1))
print("统计子字符串ok出现的次数:"+str(str_1.count('ok')))
print("将子字符串ok替换为OOO:"+str(str_1.replace('ok','OOO')))
print("将字符串首尾的lll去除:"+str_1.strip('l'))
print("将序列str_2连接在一起"+str_3.join(str_2))
print("split()切片效果,返回一个列表:"+str(str_1.split('a',1)))
基本字符串操作-Python
于 2023-10-08 14:16:00 首次发布