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 ...
随机推荐
- 吴裕雄--天生自然Android开发学习:1.2.1 使用Eclipse + ADT + SDK开发Android APP
1.前言 这里我们有两条路可以选,直接使用封装好的用于开发Android的ADT Bundle,或者自己进行配置 因为谷歌已经放弃了ADT的更新,官网上也取消的下载链接,这里提供谷歌放弃更新前最新版本 ...
- 深入理解 C/C++ 数组和指针
本文转载自CSDN@WalkingInTheWind,原文链接:https://blog.csdn.net/luckyxiaoqiang/article/details/7044380 C语言中数组和 ...
- Allure介绍
以下内容基于pytest的框架进行展示: 什么是Allure Allure是一个独立的报告插件,生成美观易读的报告,目前支持语言:Java, PHP, Ruby, Python, Scala, C#. ...
- CIA Hive Beacon Infrastructure复现1——使用Apache mod_rewrite实现http流量分发
0x00 前言 2017年11月9日维基解密公布一个代号为Vault8的文档,包含服务器远程控制工具Hive的源代码和开发文档.开发文档中的框架图显示Hive支持流量分发功能,若流量有效,转发至Hon ...
- 安装 Kali Linux 2018.1 及之后的事
本文为原创文章,转载请标明出处 目录 制作U盘启动盘 安装 Kali Linux 之后的事 更新源 配置 Zsh 配置 Vim 修改 Firefox 语言为中文 安装 Gnome 扩展 美化 安装 G ...
- idea 使用sonarlint报错解决方案
在idea使用sonarlint可能出现以下报错: Plugin 'org.sonarlint.idea' failed to initialize and will be disabled. Ple ...
- <USACO06FEB>奶牛零食Treats for the Cowsの思路
写不来dp的日常 ....就这样吧 #include<cstdio> #include<cstring> #include<iostream> #include&l ...
- JavaScript深入浅出-闭包
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 function (){ var localVal ...
- [python每日一练]--0012:敏感词过滤 type2
题目链接:https://github.com/Show-Me-the-Code/show-me-the-code代码github链接:https://github.com/wjsaya/python ...
- HTTP Continuation or non-HTTP traffic
发现一个 HTTP Continuation or non-HTTP traffic的数据包,之前没有碰到过.不懂其意义,一看长度,显示1460,与TCP segment of a reas ...