1.eval ()
function: evaluates the string str as a valid expression and returns the result of the calculation.
Syntax: eval (source[, globals[, locals]), value
Parameters:
- Source: The code object returned by a Python expression or function compile ()
- Globals: Not required. It must be dictionary.
- Locals: not required. Arbitrary map Object
>**Example:** 1Can put the list,tuple, Dict and string convert each other.2============================ 3string conversion to List4 >>>A= [[ up], [3,4], [5,6], [7,8], [9,0]] " 5 >>>type(a)6 <type ' str '> 7 >>>B= Eval(a)8 >>> PrintB9[[1,2], [3,4], [5,6], [7,8], [9,0]]Ten >>> type(b) One <type ' list '> A ============================ -Convert strings into dictionaries - >>>A= "{1: ' A ', 2: ' B '}" the >>> type(a) - <type ' str '> - >>>B= Eval(a) - >>> PrintB +{1:' A ',2:' B '} - >>> type(b) + <type ' Dict '> A ============================ atString Conversion Narimoto Group - >>>A= ([up], [3,4], [5,6], [7,8], (9,0)) " - >>> type(a) - <type ' str '> - >>>B= Eval(a) - >>> PrintB in([1,2], [3,4], [5,6], [7,8], (9,0)) - >>> type(b) to <type ' tuple '>
2.split ()
function: slices A string by specifying a delimiter, separated as num substrings if the parameter num has a specified value. and returns the segmented list of strings.
Syntax:str.split (str= "", Num=string.count (str))
Parameters:
- STR--the delimiter, which defaults to all null characters, including spaces, line breaks (\ n), tabs (\ t), and so on.
- Num--the number of splits.
Example:
str = "Line1-abcdef \nLine2-abc \nLine4-abcd"; print str.split( ); print str.split(‘ ‘, 1 );
Output:
[‘Line1-abcdef‘, ‘Line2-abc‘, ‘Line4-abcd‘] [‘Line1-abcdef‘, ‘\nLine2-abc \nLine4-abcd‘]
3.join ()
function: An array of connection strings. Generates a new string from a string, tuple, or element in the list, with the specified character (delimiter) connection
Syntax: ' Sep '. Join (SEQ)
Parameters:
Several string-handling functions in Python