- 字符串下标和切片
string = "hellow world" print(string[0:5])result = hello
- 字符串的in or not in 操作
string = "hellow world" if "e" in string : print("字母存在")
- 字符串方法upper(),lower(),isupper(),islower()
string = "hellow world" print(string.upper())result = "HELLOW WORLD"
string = "hellow World" print(string.lower())result = "hellow world"
string = "hellow World" print(string.islower())result = False
string = "hellow World" print(string.isupper())result = False
- isX方法
isalpha():判断字符串全是字母,返回True
isalnum():判断字符串是字母或者数字,返回True
isdecima():判断字符串全是数字,返回True
isspace():判断字符串全是space, 返回True
istitle():判断只有首字母大写,返回True
- 字符串方法startswith()和endswith()判断是否以传入的值开始或者结束,返回布尔值
- 字符串join()方法,讲一个字符串列表连接起来
list = ["red","blank","blue"] color = ",".join(list) print(color)result = red,blank,blue
- split()方法
list = ["red","blank","blue"] color = ",".join(list) content = color.split(",") print(content)result = ['red', 'blank', 'blue']
- rjust(),ljust()和center()(文本居中)方法对其文本
rjust(10)右边对齐,不足是个的用空格填充
- strip(),rstrip(),lstrip()删除空白字符,分别是删除两边space字符和删除右边space字符和删除左边space字符