首页 > 其他 > 详细

字符串--3 如何修改字符串之replace,find

时间:2015-12-10 21:55:14      阅读:281      评论:0      收藏:0      [点我收藏+]

>>> a = "this is word!"
>>> print a
this is word!
>>> a.replace("this","that")
‘that is word!‘
>>> a=a.replace("this","that1")
>>> print a
that1 is word!
>>> a.find(‘word‘)
9
>>> a.find(‘no‘)
-1
>>> a.find(‘woord‘)
-1
>>> a.find(‘word‘)
9
>>> a[8]
‘ ‘
>>> a[9]
‘w‘
>>> a[9:]
‘word!‘
>>> a1 = "this is %s %s" %("my","apple")
>>> print a1
this is my apple
>>> b1 = "this is {} {}" .format("apple","my")
>>> print b1
this is apple my
>>> b1 = "this is {1} {0}" .format("apple","my")
>>> print b1
this is my apple
>>> b2 = "this is {whose} {fruit}" .format(fruit="apple",whose="my")
>>> print b2
this is my apple
>>>

 

字符串--3 如何修改字符串之replace,find

原文:http://www.cnblogs.com/tom-li/p/5037230.html

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