1、 找 Find
格式:str.find(str ,start = 0 , end = len(str))
---str 指定 搜索 的 字符串
---start 开始 索引 默认值为0
---end 结束 索引 len()默认为字符串的长度
返回值
找到则返回索引值,否则返回-1。

2.index
格式与find相同
str.index(str,beg=0,end=len(string))
str -- 指定检索的字符串
beg -- 开始索引,默认为0
end -- 结束索引,默认为字符串的长度
返回值
如果包含子字符串返回开始的索引值,否则抛出异常

3.count
格式:str.count(str ,start = 0 , end = len(str))
count 用来统计字符串里某个字符出现的次数 可选择的内容在 字符串的开始与结尾的位置 =-=
=-= =-= @-@ #=# ¥-¥ +

- 替换 replace
str.replace(原内容,新内容[,max])
原内容-- 将被替换的子字符串
新内容 -- 新字符串,用于替换old子字符串
max--可选字符串, 替换不超过 max 次
将字符串中的”旧字符串“替换成”新字符串“,指定max,则替换就不超过max次。

- 分割 split
格式:str.split(str="", n=string.count(str))
str-- 分隔符,默认为所有的空格、包括空格、换行(\n)、制表符(\t)等
---n-- 分割次数
返回值
返回分割后的字符串列

6.字符大写 capitalize
str.capitalize()
把字符串的第一个字符大写
- title
把字符串每个单词首字母大写
格式 str.title
- startswith 以t(开头)(可根据自己设定值改动)
用于检查字符串是否是以指定子字符串开头,如果是则退回 True, 否则 退回 False。如果参数start和end限制,则在指定范围内检查
格式
str.startswith(str,start=0,end=len(string))
--str 检查的字符串
-- start 可选参数用于设置字符串检测的起始位置。
end -- 可选参数用于设置字符串检测的结束位置
返回值
如果检测到字符串则返回True,否则返回False

9.endwith 以设定的最后字母为结尾
格式 str.endswith("o")
检查字符串是否以最后字母结束,如果是返回True,否则返回 False.

10.lower 转换str所有内容大小写

11.upper 转换字符串中所有字母为大写
格式str.upper()

12.ljust (left just)
格式 str.ljust()
返回字符串 以左为头 并使用自己定的字符或用空格补充()中的新字符

13.rjust (right just)
格式 str.rjust()
返回字符串 以右为头 并使用自己定的字符或用空格补充()中的新字符

-
center
格式str.center( )
退回到字符串中,并使用自己所定的内容或空格来填充()的字符
image.png
15.lstrip
删除在字符串左边的空格
格式 str.lstrip( )
image.png
16.rstrip
删除在字符串右边的空格
格式str.rstrip( )
image.png
17.strip
删除字符串两侧的空格
image.png
18.partition
格式:partiton :str.partiton( 111)
把str以空格里的(111)字符分开成三部分,(111)前一部分,中间为111,111后面一部分
image.png
19.rpartiton
格式 str.rpartition("新字符")
与 partiton 相似 ,不过是从右边开始 - splitlines
格式str.splitlines(6)
按照行('\r', '\r\n', \n')分隔,返回一个包含各行作为元素的列表,如果参数 6 为 False,不包含换行符,如果为 True,则保留换行符。
21 . isalpha
格式 str.isalpha ( )
检测字符串是否只由字母组成如果字符串
有一个字符并且所有字符都是字母则返回 True,否则返回 Fals
22.isdigit
23.isalnum
24.isspace
25.join
网友评论