(注意:本文基于Python3.x)
第一种方式,for in
girl_str = "love You"
for every_char in girl_str:
print(every_char)
第二种方式,内置函数range()或xrange(),把字符串长度传进去就行
girl_str = "love You"
for index in range(len(girl_str)):
print(girl_str[index])
第三种方式,内置函数enumerate()
girl_str = "love You"
for index, every_char in enumerate(girl_str):
print(str(index) + every_char)
第四种方式,内置函数iter()
girl_str = "love You"
for every_char in iter(girl_str):
print(every_char)