首页 > 编程语言 > 详细

python笔记之字符串

时间:2016-01-10 12:58:45      阅读:187      评论:0      收藏:0      [点我收藏+]

列表,元组,字符串的相互转换:

将字符串转换为序列和元组:

>>> s="hello"

>>> list(s)
[‘h‘, ‘e‘, ‘l‘, ‘l‘, ‘o‘]
>>> tuple(s)
(‘h‘, ‘e‘, ‘l‘, ‘l‘, ‘o‘)
>>> list(tuple(s))
[‘h‘, ‘e‘, ‘l‘, ‘l‘, ‘o‘]
>>> tuple(list(s))
(‘h‘, ‘e‘, ‘l‘, ‘l‘, ‘o‘)

将序列和元组转换为字符串:

>>> "".join(list(s))
‘hello‘
>>> "".join(tuple(s))
‘hello‘
>>> str(s)
‘hello‘
>>> str(list(s))
"[‘h‘, ‘e‘, ‘l‘, ‘l‘, ‘o‘]"
>>> str(tuple(s))
"(‘h‘, ‘e‘, ‘l‘, ‘l‘, ‘o‘)"

 

 

字符串方法:

(1)find:返回子字符串第一次出现最左端索引的位置

>>> s="hello"
>>> s.find("l")
2

(2)join

(3)lower:返回小写字母

 

python笔记之字符串

原文:http://www.cnblogs.com/girl-he/p/5118099.html

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