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
'''
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动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法