この記事の例では、Python で一度に 1 文字を処理する 3 つの方法を説明します。皆さんの参考に共有してください。
具体的な方法は以下の通りです。
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 プログラミングに役立つことを願っています。