23 lines
362 B
Python
23 lines
362 B
Python
# 字符串的遍历
|
|
# 将容器里面的数据依次取出进行处理的行为 遍历
|
|
# 推荐使用for循环
|
|
# 一旦拥有索引下标 while循环也可以
|
|
|
|
# while循环遍历
|
|
str='abcdefgh'
|
|
i=0
|
|
while i<len(str):
|
|
print(str[i])
|
|
i +=1
|
|
|
|
# for循环遍历
|
|
str='ABCDEFGH'
|
|
for v in str:
|
|
print(v)
|
|
|
|
for i in range(0,len(str)):
|
|
print(str[i])
|
|
|
|
|
|
|
|
|