python字符串处理

len() 返回字符串长度

len("hello")

find() 查找内容,返回下标

a = "china"
print(a.find("c"))

startswith,endswith 判断

s = "china"
print(s.startswith("c"))

count,返回str在start和end之间在mystr里面出现的 次数

a="asdaaa"
print(a.count(a))

replace 替换字符串中指定的内容,如果指定次数count,则替换不会超过count次。

a="asdaaa"
print(a.replace('a','v'))

split 通过参数的内容切割字符串

a="1#2#3#4#5"
print(a.split('#'))

==>
['1', '2', '3', '4', '5']

upper,lower 将字符串中的大小写互换

a="china"
print(a.upper())

strip 去空格

a="     china    "
print(a.strip())

join 字符串拼接

a="a"
print(a.join("hello"))

==>
haealalao
posted @ 2025-06-26 14:06  takenika  阅读(7)  评论(0)    收藏  举报