python中字符串相关

str.split(s="", num=string.count(s))

s -- 分隔符,默认为所有的空字符,包括空格、换行(\n)、制表符(\t)等。

num -- 分割次数。

输出的是一个list。

str.strip([chars])

Python strip() 方法用于移除字符串头尾指定的字符(默认为空格或换行符)或字符序列

str.count(sub, start= 0,end=len(string))

统计字符串中的某个字符/某个子字符串出现次数

 

str.replace(old, new[, max])

把字符串中的 old(旧字符串) 替换成 new(新字符串),如果指定第三个参数max,则替换不超过 max 次

 str.isdigit()

方法检测字符串是否只由数字组成

 

 

 

参考:

http://www.runoob.com/python3/python3-string-split.html

http://www.runoob.com/python/att-string-strip.html

https://www.runoob.com/python/att-string-replace.html

 

posted @ 2018-08-12 20:49  sbj123456789  阅读(173)  评论(0编辑  收藏  举报