python string tuple list dict 相互转换的方法

 

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

码农码代码之际先赚点小钱,区块链技术应用之-Pi币 :http://www.javashuo.com/article/p-utwtqoqp-er.html

Pi 软件安卓版 连接:https://pan.baidu.com/s/1AjWTsROL2ohe24AM55eFGQhtml

或者到官方网站下载:https://minepi.com/#homeiphone

Pi 币软件 (iphone)如何下载:http://www.javashuo.com/article/p-toxtfycn-gk.html 区块链

Pi 软件 用户注册:http://www.javashuo.com/article/p-dodwbhsa-ev.html网站

Pi 界面引导(功能介绍):http://www.javashuo.com/article/p-vejbdujf-gg.htmlhtm

Pi 用户手机验证:https://www.cnblogs.com/yanxiatingyu/articles/11801772.htmlblog

因为Pi是邀请制须要邀请码为:whlgjjgyy

 

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------ip

dict = {'name': 'Zara', 'age': 7, 'class': 'First'}# 字典转为字符串,返回:<type 'str'> {'age': 7, 'name': 'Zara', 'class': 'First'}printtype(str(dict)), str(dict)# 字典能够转为元组,返回:('age', 'name', 'class')printtuple(dict)# 字典能够转为元组,返回:(7, 'Zara', 'First')printtuple(dict.values())# 字典转为列表,返回:['age', 'name', 'class']printlist(dict)# 字典转为列表printdict.values# 二、元组tup = (1, 2, 3, 4, 5)# 元组转为字符串,返回:(1, 2, 3, 4, 5)printtup.__str__()# 元组转为列表,返回:[1, 2, 3, 4, 5]printlist(tup)# 元组不能够转为字典# 三、列表nums = [1, 3, 5, 7, 8, 13, 20];# 列表转为字符串,返回:[1, 3, 5, 7, 8, 13, 20]printstr(nums)# 列表转为元组,返回:(1, 3, 5, 7, 8, 13, 20)printtuple(nums)# 列表不能够转为字典# 四、字符串# 字符串转为元组,返回:(1, 2, 3)printtuple(eval("(1,2,3)"))# 字符串转为列表,返回:[1, 2, 3]printlist(eval("(1,2,3)"))# 字符串转为字典,返回:<type 'dict'>printtype(eval("{'name':'ljq', 'age':24}"))
相关文章
相关标签/搜索