python实现每次处理一个字符的三种方法
作者:shichen2014 时间:2023-03-07 12:27:30
本文实例讲述了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,字符,方法
0
投稿
猜你喜欢
python中redis查看剩余过期时间及用正则通配符批量删除key的方法
2023-08-02 12:12:27
解析Anaconda创建python虚拟环境的问题
2023-08-01 03:58:13
Python ValueError: invalid literal for int() with base 10 实用解决方法
2023-06-18 17:00:40
Python文件操作之二进制文件详解
2021-10-23 16:44:47
php读取mysql的简单实例
2023-11-15 08:57:51
如何查询Top N及Top(M―N)记录?
2009-11-11 20:03:00
js实现的捐赠管理完整实例
2023-08-22 05:25:14
Python和Bash结合在一起的方法
2023-11-02 20:53:27
python 根据字典的键值进行排序的方法
2023-10-07 00:07:56
python操作字典类型的常用方法(推荐)
2023-01-17 17:05:33
python中Mako库实例用法
2022-01-05 16:38:21
Python中的特殊语法:filter、map、reduce、lambda介绍
2021-04-26 12:39:57
如何在ADSI中查询用户属性?
2010-06-17 12:53:00
python聚类算法选择方法实例
2023-12-01 13:51:11
Python找出微信上删除你好友的人脚本写法
2023-11-09 15:55:58
SQL Server修改表所有者
2010-02-04 08:33:00
基于python实现操作redis及消息队列
2021-08-06 22:31:29
盗亦有道 Web2.0网站优秀模仿者逐个数
2007-09-11 19:46:00
Python利用turtle库绘制彩虹代码示例
2022-03-04 03:55:01
Requests什么的通通爬不了的Python超强反爬虫方案!
2022-02-13 18:43:45