轻松python文本专题-单独处理字符串每个字符的方法汇总
2015-08-25 07:00
721 查看
场景:
用每次处理一个字符的方式处理字符串
方法:
1.使用list(str)
2.使用for遍历字符串
3.使用for解析字符串到list里面
就说到这里,谢谢大家
------------------------------------------------------------------
点击跳转零基础学python-目录
用每次处理一个字符的方式处理字符串
方法:
1.使用list(str)
>>> a='abcdefg' >>> list(a) ['a', 'b', 'c', 'd', 'e', 'f', 'g'] >>> aList=list(a) >>> for item in aList: print(item)#这里可以加入其他的操作,我们这里只是单纯使用print a b c d e f g >>>
2.使用for遍历字符串
>>> a='abcdefg' >>> for item in a : print(item)#这里可以加入其他的操作,我们这里只是单纯使用print a b c d e f g >>>
3.使用for解析字符串到list里面
>>> a='abcdefg' >>> result=[item for item in a] >>> result ['a', 'b', 'c', 'd', 'e', 'f', 'g'] >>>
就说到这里,谢谢大家
------------------------------------------------------------------
点击跳转零基础学python-目录
相关文章推荐
- Python入门(十五) socket编程
- 理解 Python 中的多线程
- 使用Python的Bottle框架写一个简单的服务接口的示例
- python3学习笔记--002--写一个类
- python3学习笔记--003--写一个自定义的包
- 利用Python监测MySQL主从状态
- Python的multiprocessing 实现多cpu 多进程
- python学习第四天
- python spark 配置
- python自我输出源程序
- 初学python,正则
- python中的split函数
- python笔记 6
- Class to connect postgres with python in psycopg2
- Python实现读取目录所有文件的文件名并保存到txt文件代码
- A daemon process class in python
- ant编译脚本执行python
- python之mock
- 有关python中的id,is 等
- 将Python脚本打包成可执行文件