Python 学习
来源:互联网 发布:居外网软件下载 编辑:程序博客网 时间:2024/06/16 14:28
1. str list 互转
def str_list(): s = "123abc" list_tmp = list(s) print (list_tmp) print (''.join(list_tmp)) print ('\n') s = "123,abc,456" list_tmp = s.split(",") print (list_tmp) print (','.join(list_tmp))
结果:
['1', '2', '3', 'a', 'b', 'c']123abc['123', 'abc', '456']123,abc,456
2. eval 使用
s = "['abc', '123', 'eed']" value = eval(s) print (type(value)) print (value)
<type 'list'>['abc', '123', 'eed']
d = "{'abc':123, 'cbd':234}" value = eval(d) print (type(value)) print (value)
结果:
<type 'dict'>{'abc': 123, 'cbd': 234}
字符串转元组
t = "(2, 'qwer', ['2wqe','abc'], 34)" value = eval(t) print (type(value)) print (value)
结果:
<type 'tuple'>(2, 'qwer', ['2wqe', 'abc'], 34)
3. 字符串截取
(1) 截掉后面的字符串
s = '00E04C800628-chrome' print (s.rstrip('-chrome'))
阅读全文
0 0
- 【Python学习】Python 关键字
- Python学习----Python基础
- 【python】:python学习笔记
- Python:Python学习总结
- Python学习-Python数据类型
- Python学习
- 学习python
- python学习
- 学习Python
- python学习
- python学习
- python学习
- python 学习
- 学习python
- Python学习
- Python 学习
- python学习
- Python学习
- 【BFS】hdu 1242 Rescue
- ImageView引用资源文件引起错误
- 设计模式-观察者模式2
- serialize与unserialize
- JQ插件写法 扩展JQ方法
- Python 学习
- SEO搜索引擎优化相关
- android 使用阿里百川电商SDK的问题
- Spring整合Mybatis
- CListCtrl控件使用方法总结
- 仿QQ聊天-listView的item多布局
- 3110: [Zjoi2013]K大数查询
- Denoise Autoencoder
- 【排序算法】折半插入排序