python实现每次处理一个字符的三种方法
更新时间:2014年10月09日 15:29:37 投稿:shichen2014
这篇文章主要介绍了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程序设计有所帮助。
相关文章
python机器学习使数据更鲜活的可视化工具Pandas_Alive
今天我分享大家一款非常棒的动画可视化工具:Pandas_Alive,它以 matplotlib 绘图为后端,不仅可以创建出令人惊叹的动画可视化,而且使用方法非常简单。本文详情如下2021-11-11


最新评论