首页 > 编程语言 > 详细

python笔记-字符串函数总结

时间:2015-11-02 15:40:47      阅读:227      评论:0      收藏:0      [点我收藏+]

字符串函数:

chr() 数字转ASCII chr(96)="a"

ord() ASCII转数字 ord("a")=96

isspace() 判断是否为空格 s="abcde" s.isspace() 返回true or false

find() 返回字符串的索引,查不到返回-1. s="abcde" s.find(“b”)返回1

index() 与find()功能一致,但若查不到则报错 

replace()  eg: s="aabbccbb"  t=s.replace("bb","BB") print t   还可以t=s.replace("bb","BB",num)修改前num个“bb”

strip() 删除字符串前后的空格,若有参数,除去参数中含有的任一字母.eg: s="abx123xba"

print s.strip("axb") 得到 “123”

 

python笔记-字符串函数总结

原文:http://www.cnblogs.com/qiangge666/p/4930147.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!