本文實例講述了python每次處理一個字符的三種方法。分享給大家供大家參考。
具體方法如下:
a_string = "abccdea" print 'the first' for c in a_string: print ord(c)+1 print "the second" result = [ord(c)+1 for c in a_string] print result print "the thrid" def do_something(c): return ord(c)+1 result = map(do_something ,a_string) print result
打印出的結果如下:
the first 98 99 100 100 101 102 98 the second [98, 99, 100, 100, 101, 102, 98] the thrid [98, 99, 100, 100, 101, 102, 98]
希望本文所述對大家的Python程序設計有所幫助。
新聞熱點
疑難解答