Conversion of Python strings, tuples, lists, and dictionaries.
I am not talking about this nonsense. I am posting Code directly to you. If the code is not well written, I 'd like to forgive you.
#-*-Coding: UTF-8-*-#1. dictionary dict = {'name': 'zara ', 'age': 7, 'class ': 'first'} # convert the dictionary into a string and return: <type 'str'> {'age': 7, 'name': 'zara ', 'class ': 'first'} print type (str (dict), str (dict) # The dictionary can be converted into a tuples, And the return value is: ('age', 'name', 'class ') print tuple (dict) # The dictionary can be converted into a tuples, and the returned result is: (7, 'zara ', 'First') print tuple (dict. values () # convert the dictionary to the list and return: ['age', 'name', 'class'] print list (dict) # convert the dictionary to the list print dict. values #2. tup = (1, 2, 3, 4, 5) # convert the tuples into strings and return print tup: (1, 2, 3, 4, 5. _ str _ () # convert the tuples to the list and return: [1, 2, 3, 4, 5] print list (tup) # The tuples cannot be converted into dictionaries #3. List nums = [1, 3, 5, 7, 8, 13, 20]; # convert the list into strings and return: [1, 3, 5, 7, 8, 13, 20] print str (nums) # convert the list into tuples and return the following values: (1, 3, 5, 7, 8, 13, 20) print tuple (nums) # The list cannot be converted into a dictionary #4. The string # is converted into a tuples and returns the following: (1, 2, 3) print tuple (eval ("(, 3) ") # convert string to list and return: [1, 2, 3] print list (eval (" (, 3) ") # convert string to dictionary and return: <type 'dict '> print type (eval ("{'name': 'ljq', 'age': 24 }"))
Articles you may be interested in:
- Python converts a string into a dictionary dict
- Examples of python list and tuples
- Python tuples (Tuple)
- Usage of tuples in basic python tutorials
- Convert a dictionary to its json string in python
- How to convert string and dictionary types in Python
- Python entry list and metadata
- List, Dictionary, tuples, and collection Data Structure in Python
- Python list, dictionary, and string operations
- Tuple tuples in Python