python字符串

来源:互联网 发布:睡眠工作 知乎 编辑:程序博客网 时间:2024/06/07 00:22


 # -*- coding:UTF-8 -*-'''Created on 2015年10月25日@author: young'''from __builtin__ import strs='abc123abc'print s.capitalize() #首字母大写print s.count('ab') #统计字符串出现次数print s.isalpha() #是否仅包含0-9A-Za—zprint s.split('123') #分割print len(s)#字符串长度print s[1] #访问下标为1的字符print s[-1] #倒数第一个print s[-0]print s[1:-1] #第二道倒数第二个print 's[1:1]='+  s[1:1]  + 'end'#前闭后开,所以没有字符print s[:-2] #同 s[0:-2]#格式化字符串print 'hello %s , I am %d years old' %('Tom',10) #格式化输出print '%d %x' % (0XFFF,4095)print 'num to str '+str(123) 

打印

Abc123abc2False['abc', 'abc']9bcabc123abs[1:1]=endabc123ahello Tom , I am 10 years old4095 fffnum to str 123


0 0