Python string/meta-ancestor/list/dictionary transfer

Source: Internet
Author: User

#-*-Coding:utf-8-*-

#author: RXS002

#1. Dictionaries

Dict = {' name ': ' Zara ', ' age ': 7, ' class ': ' First '}

#字典转换为字符串, return: <type ' str ' > {' age ': 7, ' name ': ' Zara ', ' class ': ' First '}

Print (Type (str (dict)), str (DICT))

#字典可以转为元祖, return: (' age ', ' name ', ' class ')

Print (Tuple (dict)

#字典可以转为元祖, return (7, ' Zara ', ' first ')

Print tuple (dict.values ())

#字典转为列表, return: [' age ', ' name ', ' class ']

Print List (dict)

#字典转为列表

Print (dict.values)

#2. Yuan zu

Tup = (1,2,3,4,5)

#元祖转为字符串, return: (1,2,3,4,5)

Print (tup.__str__ ())

#元祖转为列表, return: [1,2,3,4,5]

Print (list (tup))

#元祖不可以转为字典

#3. List

Nums = [1,3,5,7,8,13,20];

#列表转为字符串, return: [1,3,5,7,8,13,20]

Print (str (nums))

#列表转为元祖, return: (1,3,5,7,8,13,20)

Print (tuple (nums))

#列表不能转为字典



#4. String

#字符串转为元祖, return: (+/-)

Print (Tuple (' All-in-all '))

#字符串转为列表, return: [+]

Print (List ("eval"))

#字符串转为字典, return: <type ' dict ' >

Print (Type (eval ("{' Name ': ' SRX ', ' age ': ' 41 '}"))

Python string/meta-ancestor/list/dictionary transfer

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.