1.\(续行符):将两行字符串连接起来
2.\\(反斜杠):打印输出反斜杠符
3.\"(双引号):打印输出双引号
4.\n(换行符):换行
5.\t(制表符):将数据对齐
ord(x)
print(ord("a"))
#将字符转成对应的Unicode码
chr(x)
print(chr(97))
#将unicode码转成对应的字符
1.isalnum():判断字符串是否都是字母或者数字
a="Hello"
print(a.isalnum())
2..isalpha():判断字符串是否都是字母或中文字符
3.isdigit():判断字符串是否只包含数字
4.islower():判断字符串是否全小写
5.isupper():判断字符串是否全大写
6.isspace():判断字符串是否只包含空白
7.istitle():判断字符串是否标题化
1.title(): "标题化"的字符串
s="hello"
t=s.title()
2.lower():转换成小写
3.upper():转换成大写
4.swapcase():字符串中大写转换为小写,小写转换为大写
5.lstrip([chars]):截掉字符串左边的空格或指定字符chars
6.rstrip([chars]):截掉字符串右边的空格或指定字符chars
7.strip([chars]):调用lstrip([chars])和rstrip([chars])
8.replace(old, new[, max]):将字符串中的 old 替换成new,如果max指定,则替换不超过 max次
9.ljust(width[, fillchar]):左对齐,并使用空格(或者fllchar)填充至指定长度width的新字符串
10.rjust(width,[, fillchar]):右对齐,并使用空格(或者flchar)填充至指定长度width的新字符串
11.zfill (width):右对齐,并使用0填充至指定长度width的新字符串
12.center(width, fillchar):矩阵对齐,使用空格或者fllchar填充
1.将字符串转成列表,再修改
a="hello"
print(list(a))
2.利用split(分隔符,分割次数)函数对字符串分割
a="Hello Python,Hello everyone"
b=a.split()#默认用空字符串分割,分割次数:尽可能多
print(b)
#结果
['Hello', 'Python,Hello', 'everyone']
b=a.split(",")
print(b)
# 结果
['Hello Python', 'Hello everyone']
b=a.split(" ",1)
print(b)
#结果
['Hello', 'Python,Hello everyone']
1.count(str, beg=0,end=len(string)) :求str在字符串中出现次数,如果指定查找范围则在[beg,end)中查找
s="a b n c a s a b"
print(s.count("a",2))
#"a"为要查找出现次数的元素,2为开始查找范围的下标
2.find(str, beg= 0,end=len(string)) : 判断str是否在字符串中,如果指定查找范围则在[beg,end)中查找返回找到的起始下标,不存在返回-1
3.rfind(str, beg= 0,end=len(string):从右往左查找
4.index(str, beg=0,end=len(string)) :与find相同,只是如果str不存在,则抛出异常
5.rindex(str, beg= 0,end=len(string)):从右往左查找