python每次处理一个字符的三种方法

2023-05-20,,

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每次处理一个字符的三种方法的相关教程结束。

《python每次处理一个字符的三种方法.doc》

下载本文的Word格式文档,以方便收藏与打印。