|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 只为 于 2017-8-8 21:57 编辑
- 字符串:一旦定义不能修改。
- 1、capitalize()
- >>> str2 = 'xiaoxie'
- >>> str2.capitalize()
- 'Xiaoxie'
- 注意:返回一个新字符串,原字符串不变。
- 2、casefold()
- >>> str2 = 'DAXIExiaoxie'
- >>> str2.casefold()
- 'daxiexiaoxie'
- 注意:返回一个新字符串,原字符串不变。
- 3、center(width)
- >>> str2.center(40)
- ' DAXIExiaoxie '
- 4、count(sub[,start][,end])
- >>> str2.count('xi')
- 2
- 5、encode(encoding='utf-8',errors='strict')
-
- 6、endswith(sub[,start][,end])
- >>> str2.endswith('e')
- True
- 7、startswidth(prefix[,start][,end])
- 8、expandtabs([tabsize=8])
- >>> str2.expandtabs()
- 'I love fishc.com!'
- >>> str2.expandtabs(4)
- 'I love fishc.com!'
- 9、find(sub[,start][,end])
- >>> str2.find('efc')
- -1
- >>> str2.find('com')
- 13
- 10、rfind(sub[,start][,end])
- >>> str2 = 'xixixi'
- >>> str2.rfind('x')
- 4
-
- 11、index(sub[,start][,end])
- >>> str2.index('x')
- 0
-
- 12、rindex(sub[,start][,end])
- >>> str2.rindex('x')
- 4
- 12、isalnum()
- >>> str3 = '9ik'
- >>> str4 = '9908'
- >>> str5 = 'ldlld'
- >>> str6 = 'kjkf&$#@'
- >>> str3.isalnum()
- True
- >>> str4.isalnum()
- True
- >>> str5.isalnum()
- True
- >>> str6.isalnum()
- False
- 13、isalpha()
- >>> str3.isalpha()
- False
- >>> str4.isalpha()
- False
- >>> str5.isalpha()
- True
- >>> str6.isalpha()
- False
- 14、isdecimal()
- >>> str4.isdecimal()
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- AttributeError: 'str' object has no attribute 'isdecimal'
- 注意:python2没有此方法的,还有python3中不知道如果str是个float类型的会是什么结果
- 15、isdigit()
-
- 16、isnumeric()
-
- python中str函数isdigit、isdecimal、isnumeric的区别
- isdigit() True: Unicode数字,byte数字(单字节),全角数字(双字节),罗马数字 False: 汉字数字 Error: 无 isdecimal() True: Unicode数字,,全角数字(双字节) False: 罗马数字,汉字数字 Error: byte数字(单字节) isnumeric() True: Unicode数字,全角数字(双字节),罗马数字,汉字数字 False: 无 Error: byte数字(单字节)
-
- 17、islower()
- >>> str3 = '小甲鱼'
- >>> str3.islower()
- False
- >>> str3.isupper()
- False
- 21、isupper()
- >>> str3 = '小甲鱼'
- >>> str3.islower()
- False
- >>> str3.isupper()
- False
- 18、isspace()
-
- 19、istitle()
- >>> str5 = 'FishC'
- >>> str5.istitle()
- False
- >>> str5='Fishc'
- >>> str5.istitle()
- True
- 20、title()
- 22、join(sub)
- 23、ljust(width)
-
- 24、rjust(width)
-
- 25、zfill(width)
-
-
- 26、lower()
-
- 27、upper()
- 28、strip([chars])
-
- 29、lstrip()
-
- 30、rstrip()
- 31、partition(sub)
- 32、rpartition(sub)
-
- 33、replace(old,new[,count])
- 34、split(sep=None,maxsplit=-1)
- splitlines(([keepends]))
-
- 35、swapcase()
-
- 36、translate(table)
复制代码 |
|