Python字符串总结及使用

'''
字符串6个基本用法
join
split
find
strip
upper
lower
'''
#   print(字符串,end="") 不换行操作
#   len() 获取字符串的长度
#  c = a+b  内存中三个字符串
test = "abc"
xiabiao = 0
while xiabiao < len(test) :
    print(test[xiabiao],"\t",end="")
    xiabiao+=1
print()
for t in test:
    print(t,"\t",end="")
print()
#按索引截取字符串
print(test[1:3])
#len对列表  表示有几个元素
list1 = ["a","dsa","ewrw",546,787]
print(list1)
#替换字符串
aa = "asdasdadasdasda散打王"
print(aa.replace("a","4",100))

#帮助创建连续的数字 或从开始一直加上某个数字的集合
v = range(10)
print(v)
for n in v :
    print(n,end="")
v1 = range(0,50,3)
print(v1)
for n in v1 :
    print(n,"\t",end="")
#输出字符串说对应的索引
print()
for n in range(0,len(aa)) :
    print(n,"\t",aa[n])

运行结果

 

posted @ 2018-02-27 16:08  FreeSince  阅读(176)  评论(0)    收藏  举报