string

# !D:\Python
# Filename:str_methods.py

name = 'Swaroop' # this is a string object
if name.startswith('Swa'):
    print 'Yes, the string startwith "Swa"'

if 'a' in name:
    print 'Yes, it contains the string "a"'

if name.find('war') != -1:
    print 'Yes, it contains the string "war"'

delimiter = '_*_'
mylist = ['Brazil', 'Russia', 'India', 'China']
print delimiter.join(mylist)

结果:
Yes, the string startwith "Swa"
Yes, it contains the string "a"
Yes, it contains the string "war"
Brazil_RussiaIndia*_China

====================

最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 12,141评论 0赞 23
  • 概述 在分析String的源码之前,打算先介绍一点关于JVM的内存分布,这样有助于我们更好地去理解String的设...
    wustor阅读 936评论 0赞 2
  • 早晨起来后收拾了一下家里,洗刷完了,没有吃早饭就开车往娘家赶路。现在每次回家都喜欢走大坝,路边的垂柳由原来的淡黄色...
    胡宝琴阅读 481评论 0赞 2
  • 近离塾前半时,一仪容端庄之女子携三人款款入室。眉目含笑,温婉清扬。其身似萦缕缕茶香,乌云如瀑之发盘于顶;华美之紫红...
    歆夜夜阅读 568评论 0赞 0
  • 下班时间到了,看着眼前还没做完的培训分享材料,无奈的拿起电话打给爸爸,请爸妈帮忙带带丫。 爸爸接到我的求助电话,不...
    学前班77阅读 257评论 3赞 0

友情链接更多精彩内容