python_字符串&列表&元组&字典之间转换学习

#!/usr/bin/env/python
#-*-coding:utf-8-*- #Author:LingChongShi #查看源码Ctrl+左键 #数据类型之间的转换
Str='www.baidu.com'
'''一、str--->list'''
print('str-->list:',Str.split('.'),type(Str.split()))
'''二、str--->tuple'''
print('str--->tuple',Str.partition('.'),type(Str.partition('.')))
'''三、str--->dict'''
Str='{"name":"xiaoshao","age":10,"address":"xian"}'
print('str--->dict:',eval(Str),type(eval(Str))) List= ['www', 'baidu', 'com']
'''一、list--->str'''
print('list--->str:','.'.join(List),type('.'.join(List)))
'''二、list--->tuple'''
print('list--->tuple:',tuple(List),type(tuple(List)))
'''三、list--->dict'''
print('list--->dict:',dict(enumerate(List)),type(dict(enumerate(List))))
List1= [1,2,3]
print('list--->dict:',dict(zip(List,List1)),type(dict(zip(List,List1))))
List2= [['www',1],['baidu',2],['com',3]]
print('list--->dict:',dict(List2),type(dict(List2))) Tuple=('www', 'baidu', 'com')
'''一、tuple--->str'''
print('tuple--->str:','.'.join(Tuple),type('.'.join(Tuple)))
'''二、tuple--->list'''
print('tuple--->list:',list(Tuple),type(list(Tuple)))
'''三、tuple--->dict'''
print('tuple--->dict:',dict(enumerate(Tuple)),type(dict(enumerate(Tuple)))) Dict={'name':'xiaoshao','age':10,'address':'xian'}
'''一、dict--->str'''
print('dict--->str:',str(Dict),type(str(Dict)))
'''二、dict--->list'''
print('dict--->list:',list(Dict.keys()),type(list(Dict.keys())))
print('dict--->list:',list(Dict.values()),type(list(Dict.values())))
'''三、dict--->tuple'''
print('dict--->tuple:',tuple(Dict.keys()),type(tuple(Dict.keys())))
print('dict--->tuple:',tuple(Dict.values()),type(tuple(Dict.values())))

python_字符串&列表&元组&字典之间转换学习的更多相关文章
- Python笔记【5】_字符串&列表&元组&字典之间转换学习
#!/usr/bin/env/python #-*-coding:utf-8-*- #Author:LingChongShi #查看源码Ctrl+左键 #数据类型之间的转换 Str='www.baid ...
- python字符串/列表/元组/字典之间的相互转换(5)
一.字符串str与列表list 1.字符串转列表 字符串转为列表list,可以使用str.split()方法,split方法是在字符串中对指定字符进行切片,并返回一个列表,示例代码如下: # !usr ...
- Python第三天 序列 5种数据类型 数值 字符串 列表 元组 字典 各种数据类型的的xx重写xx表达式
Python第三天 序列 5种数据类型 数值 字符串 列表 元组 字典 各种数据类型的的xx重写xx表达式 目录 Pycharm使用技巧(转载) Python第一天 安装 shell ...
- Python第三天 序列 数据类型 数值 字符串 列表 元组 字典
Python第三天 序列 数据类型 数值 字符串 列表 元组 字典 数据类型数值字符串列表元组字典 序列序列:字符串.列表.元组序列的两个主要特点是索引操作符和切片操作符- 索引操作符让我 ...
- python字符串 列表 元组 字典相关操作函数总结
1.字符串操作函数 find 在字符串中查找子串,找到首次出现的位置,返回下标,找不到返回-1 rfind 从右边查找 join 连接字符串数组 replace 用指定内容替换指定内容,可以指定次数 ...
- python 字符串,列表,元组,字典相互转换
1.字典 dict = {'name': 'Zara', 'age': 7, 'class': 'First'} 字典转为字符串,返回:<type 'str'> {'age': 7, 'n ...
- Python自动化开发 - 字符串, 列表, 元组, 字典和和文件操作
一.字符串 特性:字符串本身不可修改,除非字符串变量重新赋值.Python3中所有字符串都是Unicode字符串,支持中文. >>> name = "Jonathan&q ...
- Python数据类型-布尔/数字/字符串/列表/元组/字典/集合
代码 bol = True # 布尔 num = 100000000; # 数字 str = "fangbei"; # 字符串 str_cn = u"你好,方倍" ...
- Python 整数 长整数 浮点数 字符串 列表 元组 字典的各种方法
对于Python, 一切事物都是对象,对象基于类创建!! 注:查看对象相关成员var,type, dir 一.整数 如: 18.73.84 每一个整数都具备如下需要知道的功能: def bit_len ...
随机推荐
- [LC] 7. Reverse Integer
Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Examp ...
- Ajax 请求参数过多导致 400 错误 and BCryptPasswordEncoder 加密判断
2019/06/19 先分享一种密码加密方式: Spring Security 提供了 BCryptPasswordEncoder类, 实现Spring的PasswordEncoder接口使用BCry ...
- Caused by: com.alibaba.fastjson.JSONException: syntax error, expect {, actual [, pos 0, fastjson-version 1.2
环境: vue.js 问题: 当添加评论时 重新查询数据刷新数据控制台异常Caused by: com.alibaba.fastjson.JSONException: syntax error, ex ...
- fiddler https 您的连接不是私密连接 解决方法(不明原理但是照着做成功了,记录下)
在桌面找到生成的证书 打开chrome chrome://settings/ 导入证书 再次运行fiddler,依次点击Tools下的Options,然后点HTTPS选项卡,再点击actions下的R ...
- log4j不输出日志错误分析
1.rootLogger不输出 代码如下: 配置文件代码: log4j.rootLogger=info, R,userLog log4j.appender.R=org.apache.log4j.Rol ...
- 初等数论-Base-2(扩展欧几里得算法,同余,线性同余方程,(附:裴蜀定理的证明))
我们接着上面的欧几里得算法说 扩展欧几里得算法 扩展欧几里德算法是用来在已知a, b求解一组x,y,使它们满足贝祖等式\(^①\): ax+by = gcd(a, b) =d(解一定存在,根据数论中的 ...
- <NOI2002>银河英雄传说の思路
emm并没有什么好说的.毕竟我这个蒟蒻都能yy出来 #include<cstring> #include<cstdio> #include<iostream> #i ...
- 携程酒店DevOps测试实践
作者简介 王幸福,携程酒店研发部高级测试经理,负责无线自动化测试相关工作.在测试框架和平台研发.移动测试.DevOps等领域有着丰富的经验. 如今很多大型互联网公司.创新型企业都在积极地进行DevOp ...
- Coding and Paper Letter(十五)
资源整理. 1.Nature Climate Change论文"Higher temperatures increase suicide rates in the United States ...
- 确认下眼神!有没有遇上对的工资(测试leader)
屏蔽敏感信息,直接上图: ▼