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 "", line 1, in 8 string.count() 9 TypeError: count() takes at least 1 argument (0 given)10 >>> string.count('a') 获得字符串的数目11 212 >>> string.find('c') 获得字符串的起始位置13 1014 >>> string[10] 第十个元素15 'c'16 >>> string.isalnum() 是否包含0-1A-Z,a-z17 False18 >>> string.isalpha()19 False20 >>> string.isdigit()是否仅包含字母21 False22 >>> string.islower()是否均为小写23 False24 >>> string.istitle()字符串中单词是否首字母大写25 False26 >>> 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 "", line 1, in 9 A.join(string)10 NameError: name 'A' is not defined11 >>> '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 " ", line 1, in 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