您的位置:首页 > 编程语言 > Python开发

python字符串

2015-10-27 09:02 393 查看
# -*- coding:UTF-8 -*-
'''
Created on 2015年10月25日

@author: young
'''
from __builtin__ import str
s='abc123abc'
print s.capitalize() #首字母大写

print s.count('ab') #统计字符串出现次数

print s.isalpha() #是否仅包含0-9A-Za—z

print 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)


打印
Abc123abc
2
False
['abc', 'abc']
9
b
c
a
bc123ab
s[1:1]=end
abc123a
hello Tom , I am 10 years old
4095 fff
num to str 123
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python