# 字符串 # " " '' 借助函数 。 .format() %。......... s1 = "nihao" # 索引--index [] print(s1[0]) print(s1[1]) print(s1[2]) print(s1[3]) print(s1[4]) # n # i # h # a # o # s1[index]-----索引 0,1,2,3....... s1 = "nihao" i = 0 while i <= 4: print(s1[i]) i+=1 # n # i # h # a # o # n s1 = "nihao" for i in s1: print(i) # n # i # h # a # o # 切片 取内容 s2 = "nihao" print(s2[1:]) # ihao print(s2[:2]) # ni print(s2[0:2]) # ni print(s2 [1:2]) # i print(s2[2:5]) # hao # 步长 0,1,2...... s3 = "nihaome" print(s3[1::3]) # io print(s3[::3]) # nae print(s3[::2]) # nhoe print(s3[::]) # nihaome print(s3[::-1]) # -1 倒叙取 # emoahin print(s3[-2:-6:-1]) # moah print(s3[2:-1]) # haom print(s3[::-2]) # eohn # 练习应用 s4 = "yukebanwozi" for l in s4: print(l) l1 = "suiiabn" o = 0 while o <=6: print(l1[o]) o+=1 i1 = "suibian" print(i1[:6]) # print() i2 = "nihaomewk" print(i2[2::5])