Python string/tuple/list/dictionary cross-transfer

Source: Internet
Author: User

Python string/tuple/list/dictionary cross-transfer

--coding:utf-8--1, Dictionary dict = {' name ': ' Zara ', ' age ': 7, ' class ': ' First '} dictionary converted to string, return: <type ' str ' > {' age ': 7, ' name ': ' Z Ara ', ' class ': ' First '}print type (str (dict)), the STR (dict) dictionary can be converted to tuples, returning: (' age ', ' name ', ' class ') the print tuple (dict) dictionary can be converted to tuples, Return: (7, ' Zara ', ' first ') print tuple (dict.values ()) dictionary to list, return: [' age ', ' name ', ' class ']print list (dict) dictionary to list print Dict.values2, tuple tup= (1, 2, 3, 4, 5) tuples converted to strings, returned: (1, 2, 3, 4, 5) print tup.str () tuples to list, return: [1, 2, 3, 4, 5]print list (tup) tuples cannot be converted to  Dictionary 3, List nums=[1, 3, 5, 7, 8, 13, 20]; list converted to string, return: [1, 3, 5, 7, 8,, 20]print str (nums) to tuple, return: (1, 3, 5, 7, 8, and) print The list of tuple (nums) can not be converted to dictionary 4, string string to tuple, return: (1, 2, 3) Print tuple (eval ()) string to list, return: [1, 2, 3]print list (eval ()) The string is converted to a dictionary, returning: <type ' dict ' >print type (eval ({' name ': ' Ljq ', ' Age ': 24}))

Python string/tuple/list/dictionary cross-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.