python之字符串
来源:互联网 发布:ipv6有什么好处知乎 编辑:程序博客网 时间:2024/04/28 09:40
接字符串的切片
字符串的判断子串
判断字符 | 字符串是否属于字符串,用 字符/字符串 in 字符串
In [5]: a = 'hello world'In [6]: 'a' in a ##判断字符a是否属于字符串aOut[6]: FalseIn [7]: 'ello' in a ##判断字符串ello是否属于字符串aOut[7]: TrueIn [8]: 'elo' in aOut[8]: FalseIn [9]: 'w' in aOut[9]: True
字符串的重复、连接以及计算长度
重复:字符串*(n) ##n为重复的次数
连接:字符串+字符串
计算长度:len(字符串)
In [1]: print 'hello '*10hello hello hello hello hello hello hello hello hello hello In [2]: print 'hello'+'world'helloworldIn [3]: a = 'hello westos@@'In [4]: len(a)Out[4]: 14
字符串常用操作
字符串的操作有:
In [5]: aOut[5]: 'hello westos@@'In [6]: a.a.capitalize a.format a.isupper a.rindex a.stripa.center a.index a.join a.rjust a.swapcasea.count a.isalnum a.ljust a.rpartition a.titlea.decode a.isalpha a.lower a.rsplit a.translatea.encode a.isdigit a.lstrip a.rstrip a.uppera.endswith a.islower a.partition a.split a.zfilla.expandtabs a.isspace a.replace a.splitlines a.find a.istitle a.rfind a.startswith
可以使用help()查看字符串的帮助
In [6]: help(a.format) ##查看帮助Help on built-in function format: ##帮助format(...) S.format(*args, **kwargs) -> string Return a formatted version of S, using substitutions from args and kwargs. The substitutions are identified by braces ('{' and '}').(END)
常用:
a.isalnum ##判断是否是字母或数字a.isalpha ##判断是否是字母a.isdigit ##判断是否是数字a.islower ##判断是否是小写字母a.isupper ##判断是否是大写字母a.isspace ##判断是否是英文空格a.istitle ##判断是否是标题(开头字母为大小写)
阅读全文
0 0
- python之字符串处理
- python之字符串处理
- python编程之字符串
- python笔记之字符串
- python 字符串之strip
- Python学习之字符串
- python之字符串
- Python学习之字符串
- python之字符串
- python基础之字符串
- python基础之字符串
- Python序列之字符串
- Python学习之字符串
- Python基础教程之字符串
- python之字符串
- Python之字符串
- Python之反转字符串
- python学习之字符串
- 备忘录模式案例
- Kali2 SSH连接不上的解决方法
- 主体
- Java初级入门之 Five 面向对象特征
- 《机器学习实战》学习笔记-[2]-K近邻_网站约会实例
- python之字符串
- 机器学习之KNN算法
- 随滚轮滚动的时间轴demo
- 文件和流笔记
- Admiral UVA
- 基于arduino和蓝牙通信的智能窗户控制系统
- 决策树可视化环境搭建
- 算法概论习题8.8 证明精确的4SAT问题是NP完全问题
- 关注国情民情,从身边做起