Python语言技术文档

微信小程序技术文档

php语言技术文档

jsp语言技术文档

asp语言技术文档

C#/.NET语言技术文档

html5/css技术文档

javascript

点击排行

您现在的位置:首页 > 技术文档 > Python编程技巧

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

来源:中文源码网    浏览:110 次    日期:2024-05-10 15:28:47
【下载文档:  python实现每次处理一个字符的三种方法.txt 】


python实现每次处理一个字符的三种方法
本文实例讲述了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程序设计有所帮助。

相关内容