python string与list互转
2016-01-30 09:11
591 查看
因为python的read和write方法的操作对象都是string。而操作二进制的时候会把string转换成list进行解析,解析后重新写入文件的时候,还得转换成string。
>>> import string
>>> str = 'abcde'
>>> list = list(str)
>>> list
['a', 'b', 'c', 'd', 'e']
>>> str
'abcde'
>>> str_convert = ''.join(list)
>>> str_convert
'abcde'
>>>
/article/7361479.html
>>> import string
>>> str = 'abcde'
>>> list = list(str)
>>> list
['a', 'b', 'c', 'd', 'e']
>>> str
'abcde'
>>> str_convert = ''.join(list)
>>> str_convert
'abcde'
>>>
/article/7361479.html
相关文章推荐
- Python 8.4 进程 vs 线程
- python学习第十三课
- 『Python』序列学习总结之一 ——列表
- python 爬取微信文章
- collections_python
- 学习Python语言---If语句
- 解决bs4在Python 3.5下出现“ImportError: cannot import name 'HTMLParseError'”错误
- 学习Python语言-列表和for循环
- 《笨办法学Python》 第27课手记
- python:为什么reversed()之后,第二次以后的list()得到的结果都是空?
- python 类型之 set
- python class中的@staticmethod
- python大型项目 个人学习中心
- 【Python】用base64和RC4给数据加密/解密
- Python之socket
- Python爬虫实战(5):模拟登录淘宝并获取所有订单
- Python爬虫实战(3):计算大学本学期绩点
- Python爬虫实战(2):百度贴吧帖子
- Python爬虫实战(1):爬取糗事百科段子
- Python爬虫入门(8):Beautiful Soup的用法