一:join用法spa
字符串迭代添加元素字符串
s='dsfhhewfe' s1='*'.join(s) print(s1)
打印结果:for循环
d*s*f*h*h*e*w*f*e循环
二:字符串循环(与for循环连用,能够添加break,continue)im
1 for循环与break连用db
for i in s: if i=='h': break print(i)
打印结果img
2 for循环与continue连用while
for i in s: if i=='h': continue print(i)
打印结果co
三:while与else连用join
while 1: pass else: pass
四:for与else连用
s='alkshfdfhg' for i in s: if i=='h': continue print(i) else: print('666')
打印结果