Python3.4 1文字ずつ処理

2714 ワード

"""
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 ]

実行結果:
bixiaopeng@bixiaopengtekiMacBook-Pro python_text$ python del_with_a_character.py
##          : m
##          : y
##          :
##          : n
##          : a
##          : m
##          : e
##          :
##          : i
##          : s
##          :
##          : b
##          : i
##          : x
##          : i
##          : a
##          : o
##          : p
##          : e
##          : n
##        : m
##        : y
##        :
##        : n
##        : a
##        : m
##        : e
##        :
##        : i
##        : s
##        :
##        : b
##        : i
##        : x
##        : i
##        : a
##        : o
##        : p
##        : e
##        : n
##        : g
['m', 'y', ' ', 'n', 'a', 'm', 'e', ' ', 'i', 's', ' ', 'b', 'i', 'x', 'i', 'a', 'o', 'p', 'e', 'n', 'g']
##   list: m
##   list: y
##   list:
##   list: n
##   list: a
##   list: m
##   list: e
##   list:
##   list: i
##   list: s
##   list:
##   list: b
##   list: i
##   list: x
##   list: i
##   list: a
##   list: o
##   list: p
##   list: e
##   list: n
##   list: g
  map  : m
  map  : y
  map  :
  map  : n
  map  : a
  map  : m
  map  : e
  map  :
  map  : i
  map  : s
  map  :
  map  : b
  map  : i
  map  : x
  map  : i
  map  : a
  map  : o
  map  : p
  map  : e
  map  : n
  map  : g
##       : m
##       : y
##       :
##       : n
##       : a
##       : m
##       : e
##       :
##       : i
##       : s
##       :
##       : b
##       : i
##       : x
##       : i
##       : a
##       : o
##       : p
##       : e
##       : n
##       : g

微信公衆口座番号:wirelessqa
作成者について:
作者:毕小朋|老毕邮箱:[email protected]
微博:@WirelessQAブログ:http://blog.csdn.net/wirelessqa