"""
Python3.4【文本】之每次处理一个字符
"""
test_str = "my name is bixiaopeng"
for x in range( 0, len(test_str)-1):
print ("## 通过索引遍历字符串: " + test_str[x])
for x in test_str:
print ("## 直接遍历字符串: " + x)
thelist = list(test_str)
print (thelist) #['m', 'y', ' ', 'n', 'a', 'm', 'e', ' ', 'i', 's', ' ', 'b', 'i', 'x', 'i', 'a', 'o', 'p', 'e', 'n', 'g']
for x in thelist:
print ("## 遍历list: " + x)
def printstr(a):
print ("使用map遍历: " + a)
list(map(printstr,test_str)) #注意: python3以后必须使用list来打印map的结果
[print ("## 列表推导遍历: " + i) for i in test_str ]