python学习笔记1(字符串操作)

#字符串操作
#example1  字符串截取
strs = '123456789'

print strs[0:1]  
#1 输出0到1的字符

print strs[1:6]
#23456 输出1~6的字符串

num = 18
strs = '00000' + str(num) #合并字符串
print strs[-5:]
#00018 输出字符串右5位

#example2 字符串替换
str = 'akakak'
str = str.replace('k',8) #将字符串里的卡全部替换成8
print str
#'a8a8a8'

#example3 字符串查找
str = 'a,hello'
print str.find('hello') #查找hello
#2

#example4 字符串分割
str = 'a,b,c,d'
strlist = str.split(',') #用逗号分割字符串,并保存到列表
for value in strlist:
	print value

#a b c d

  

posted @ 2013-06-26 20:11  我叫龙弟弟  阅读(191)  评论(0编辑  收藏  举报