1 >>> string="i am from china 323HELLOstudet" 2 >>> string.capitalize() 将字符传第一个字母大写 3 'I am from china 323hellostudet' 4 >>> string.count() 5 6 Traceback (most recent call last): 7 File "<pyshell#2>", line 1, in <module> 8 string.count() 9 TypeError: count() takes at least 1 argument (0 given) 10 >>> string.count('a') 获得字符串的数目 11 2 12 >>> string.find('c') 获得字符串的起始位置 13 10 14 >>> string[10] 第十个元素 15 'c' 16 >>> string.isalnum() 是否包含0-1A-Z,a-z 17 False 18 >>> string.isalpha() 19 False 20 >>> string.isdigit()是否仅包含字母 21 False 22 >>> string.islower()是否均为小写 23 False 24 >>> string.istitle()字符串中单词是否首字母大写 25 False 26 >>> string.isspace() 所有字符是否均为空白字符 27 False
1 >>> string.isupper() 是否均为大写字母 2 False 3 >>> string.join('A') 4 'A' 5 >>> A.join(string) 6 7 Traceback (most recent call last): 8 File "<pyshell#16>", line 1, in <module> 9 A.join(string) 10 NameError: name 'A' is not defined 11 >>> 'A'.join(string) 连接字符串 ******* 12 'iA AaAmA AfArAoAmA AcAhAiAnAaA A3A2A3AHAEALALAOAsAtAuAdAeAt' 13 >>> string.lower() 将字符串全部转换为小写 14 'i am from china 323hellostudet' 15 >>> string.split() 默认以空格分割 16 ['i', 'am', 'from', 'china', '323HELLOstudet'] 17 >>> string.split('s') 以s分割 18 ['i am from china 323HELLO', 'tudet'] 19 >>> string.swapcase() 将大写转换为小写,小写转换为大写 20 'I AM FROM CHINA 323helloSTUDET' 21 >>> string.title() 将字符串中单词首字母大写 22 'I Am From China 323Hellostudet' 23 >>> string.uper() 将全部字母转换为大写 24 25 Traceback (most recent call last): 26 File "<pyshell#23>", line 1, in <module> 27 string.uper() 28 AttributeError: 'str' object has no attribute 'uper' 29 >>> string.upper() 30 'I AM FROM CHINA 323HELLOSTUDET' 31 >>> len(string) 字符串长度 32 30