Python之路 day2 字符串/元组/列表/字典互转
#-*-coding:utf-8-*- #1、字典
dict = {'name': 'Zara', 'age': 7, 'class': 'First'} #字典转为字符串,返回:<type 'str'> {'age': 7, 'name': 'Zara', 'class': 'First'}
print type(str(dict)), str(dict) #字典可以转为元组,返回:('age', 'name', 'class')
print tuple(dict)
#字典可以转为元组,返回:(7, 'Zara', 'First')
print tuple(dict.values()) #字典转为列表,返回:['age', 'name', 'class']
print list(dict)
#字典转为列表
print dict.values #2、元组
tup=(1, 2, 3, 4, 5) #元组转为字符串,返回:(1, 2, 3, 4, 5)
print tup.__str__() #元组转为列表,返回:[1, 2, 3, 4, 5]
print list(tup) #元组不可以转为字典 #3、列表
nums=[1, 3, 5, 7, 8, 13, 20]; #列表转为字符串,返回:[1, 3, 5, 7, 8, 13, 20]
print str(nums) #列表转为元组,返回:(1, 3, 5, 7, 8, 13, 20)
print tuple(nums) #列表不可以转为字典 #4、字符串 #字符串转为元组,返回:(1, 2, 3)
print tuple(eval("(1,2,3)"))
#字符串转为列表,返回:[1, 2, 3]
print list(eval("(1,2,3)"))
#字符串转为字典,返回:<type 'dict'>
print type(eval("{'name':'ljq', 'age':24}"))
Python之路 day2 字符串/元组/列表/字典互转的更多相关文章
- python 小白(无编程基础,无计算机基础)的开发之路,辅助知识6 python字符串/元组/列表/字典互转
神奇的相互转换,小白同学可以看看,很有帮助 #1.字典dict = {'name': 'Zara', 'age': 7, 'class': 'First'} #字典转为字符串,返回:<type ...
- python字符串/元组/列表/字典互转
#-*-coding:utf-8-*- #1.字典 dict = {'name': 'Zara', 'age': 7, 'class': 'First'} #字典转为字符串,返回:<type ' ...
- 转:python字符串/元组/列表/字典互转
#-*-coding:utf-8-*- #1.字典 dict = {'name': 'Zara', 'age': 7, 'class': 'First'} #字典转为字符串,返回:<type ...
- 【转】python字符串/元组/列表/字典互转
#-*-coding:utf-8-*- #1.字典 dict = {'name': 'Zara', 'age': 7, 'class': 'First'} #字典转为字符串,返回:<type ' ...
- python基础之数据类型/字符串/元组/列表/字典
Python 数据类型 数字类型: int整型,long 长整型(在python3.0里不区分整型和长整型).float浮点型:complex复数(python中存在小数字池:-5--257):布尔值 ...
- python数据类型:序列(字符串,元组,列表,字典)
序列通常有2个特点: 1,可以根据索引取值 2,可以切片操作 字符串,元组,列表,字典,都可以看做是序列类型 我的操作环境:Ubuntu16.04+python2.7 一.字符串类型 >按索引获 ...
- 小白的Python之路 day2 字符串操作 , 字典操作
1. 字符串操作 特性:不可修改 name.capitalize() 首字母大写 name.casefold() 大写全部变小写 name.center(50,"-") 输出 '- ...
- Python之路 day2 字符串函数
#Author:ersa name = "ersa" #首字母大写capitalize() print(name.capitalize()) name = "my nam ...
- python_way ,day2 字符串,列表,字典,时间模块
python_way ,day2 字符串,列表,字典,自学时间模块 1.input: 2.0 3.0 区别 2.0中 如果要要用户交互输入字符串: name=raw_input() 如果 name=i ...
随机推荐
- Spring学习笔记之三----基于Annotation的Spring IOC配置
使用Annotation 来创建Bean有两种方式 在配置类中创建bean(配置类是指标注为@Configuration的类),在配置类中每一个创建bean的方法都应该标注为@Bean,可以在@Bea ...
- activiti-5.15备份记录
activiti-5.15用户手册翻译完成 源码下载地址:http://activiti.org/download.html在线浏览地址: http://www.mossle.com/docs/act ...
- 手机APP功能测试经验分享2016.06.06
1.登录时,Android和IOS同样的操作,提示信息不一致: 2.注册等页面切换成横屏容易不兼容.把内存卡去掉,再发送图片.音频.视频容易出错. 3.Android和IOS同样的功能,同样的原型图, ...
- java 观察者模式
/** 抽象的观察者 */ public interface Watcher { // status 为 被被观察着传递过来的状态 public void update(String status); ...
- edittext把软键盘上的回车键改为搜索、发送或者 下一步,窗口随软键盘弹出而改变。
http://m.blog.csdn.net/article/details?id=51350501 以上博文讲解很详细. 如图所示,有时候为了布局美观,在搜索时没有搜索按钮,而是调用软件盘上的按钮. ...
- Prince2七大主题之风险
Prince2七大主题之风险 我们前几个节学习了PRINCE2七大主题的商业论证.组织.质量和计划,今天我们开展对于风险模块的讲解. 风险:目的是识别.评估和控制不确定性,从而提高项目的成功率.P ...
- java开发中中文乱码总结
1.jsp页面内容显示乱码 这种乱码原因很简单,一般的工具或解码程序对中文字符解析时采用默认的解码方式: <%@ page contentType="text/html; charse ...
- Python作业 1
用户有三次机会登录,登录成功,显示欢迎界面. 三次登录失败,账户被锁定,下次登录失败. 思路: 1:流程控制:for或者while循环,达到三次检测目的. 2:文件操作. 检测文档,一旦发现输入账户名 ...
- java full gc
转自:http://blog.sina.com.cn/s/blog_7a351012010163a1.html
- 今天谈谈流,什么是IO流?
无标题 (5) :first-child { margin-top: 0; } blockquote > :last-child { margin-bottom: 0; } img { bord ...