1, 字符串: 双引号或单引号中的数据
输出: print()
输入: input()
切片:[起始下标: 结束下标: 步长] PS: 选取区间属于左闭右开型.[1:5:1] [5:1:-1]
常见操作:
find: mystr.find(str, start=0, end=len(mystr)) 存在返回索引值, 否则返回 - 1.
index: mystr.index(str, start=0, end=len(mystr)) 同 find 一样, 存在返回索引, 不存在会报异常.
count: mystr.count(str, start=0, end=len(mystr) 返回 str 在 start 和 end 之间在 mystr 里面出现的次数.
replace: mystr.replace(str1, str2, mystr.count(str1)) 把 mystr 中的 str1 替换成 str2, 如果 count 指定, 则替换不超过 count 次.
split: mystr.split(str=" ", maxsplit) 以 str 为分隔符切片 mystr, 如果 maxsplit 有指定值, 则仅分隔 maxsplit 个字符串.
capitalize: mystr.capitalize() 把字符串的第一个字符大写.
title: mystr.title() 把字符串的每个单子首字母大写.
startswith: mystr.startswith(obj) 检车字符串是否是以 obj 开头, 是返回 True, 否返回 False.
endswith: mystr.endswith(obj) 检车字符串是否是以 obj 结束, 是返回 True, 否返回 False.
lower: mystr.lower() 转换 mystr 中所有大写字符为小写.
upper: mystr.upper() 转换 mystr 中所有小写字符为大写.
ljust: mystr.ljust(width) 返回一个原字符串左对齐, 并使用空格填充至长度 width 的新字符串.
rjust: mystr.rjust(width) 返回一个原字符串右对齐, 并使用空格填充至长度 width 的新字符串.
center: mystr.center(width) 返回一个原字符串居中, 并使用空格填充至长度 width 的新字符串.
lstrip: mystr.lstrip() 删除 mystr 左边的空白字符.
rstrip: mystr.rstrip() 删除 mystr 右边的空白字符.
strip: mystr.strip() 删除 mystr 两边的空白字符.
rfind: mystr.rfind(str, start=0,end=len(mystr)) 类似于 find() 函数, 不过是从右边开始查找.
rindex: mystr.rindex(str, start=0,end=len(mystr)) 类似于 index() 函数, 不过是从右边开始查找.
partition: mystr.partition(str) 把 mystr 以 str 分割成三部分, str 前, str 和 str 后.
rpartition: mystr.partition(str) 类似于 partition() 函数, 不过是右边开始.
splitlines: mystr.splitlines() 按照行分隔, 返回一个包含各行作为元素的列表.
isalpha: mystr.isalpha() 如果 mystr 所有字符串都是字母, 则返回 True, 否则返回 False.
isdigit: mystr.isdigit() 如果 mystr 只包含数字则返回 True, 否则返回 False.
isalnum: mystr.isalnum() 如果 mystr 所有字符都是字母或数字则返回 True, 否则返回 False.
isspace: mystr.isspace() 如果 mystr 中只包含空格, 则返回 True, 否则返回 False.
join: str.join( mystr) mystr 中每个字符后面插入 str, 构造出一个新的字符串.
来源: http://www.bubuko.com/infodetail-2716426.html