python join function

1  function: string.join ()
 2  
. 3  the Python there join () and the os.path.join () two functions, the following specific effect:
 . 4      join (): connecting string array. A string, a tuple, in the list element to specify character (separator) connected to generate a new string
 . 5      the os.path.join (): returns the rear combination plurality of paths
 . 6  
. 7  a, the function described
 . 8 . 1 , join () function
 . 9  
10 syntax:   ' On Sep ' .join (SEQ)
 . 11  
12 is  parameter Description
 13 is  On Sep: delimiter. Can be empty
 14  seq: sequence element to be connected, a string, a tuple, the dictionary
 15  above syntax namely: sep as a separator, and the combined seq all the elements into a new string
 16  
. 17  Return Value: returns a string delimiter sep connected after each generated element
 18 is  
. 19   
20 is  
21 is 2, Os.path.join () function
 22 is  
23 is  Syntax: the os.path.join (path1 [, path2 [, ......]])
 24  
25  Return Value: returns the plurality of combinations of paths
 26 is  
27  Note: before the first parameter is ignored absolute path
 28  
29  
30  # of operation sequences (respectively using 'and': 'as a separator) 
31 is    
32 >>> SEQ1 = [ ' Hello ' , ' Good ' , ' Boy ' , ' doiido ' ]
 33 is >>> Print  '  ' .join (SEQ1)
 34 is  Hello Good Boy doiido
 35 >>>print ': ' .Join (SEQ1)
 36  Hello: Good: Boy: doiido
 37 [    
38 is    
39  # manipulate strings 
40    
41 is >>> SEQ2 = " Hello doiido Good Boy " 
42 is >>> Print  ' : ' .join (SEQ2)
 43 is  H: E: L: L: O:: G: O: O: D:: B: O: Y:: D: O: I: I: D: O
 44 is    
45    
46 is  # operates tuples 
47    
48 SEQ3 = >>> ( ' Hello ' , ' Good ' , ' Boy ' , 'doiido ')
 49 >>> Print  ' : ' .join (SEQ3)
 50  Hello: Good: Boy: doiido
 51 is    
52 is    
53 is  # dictionary operation 
54 is    
55 >>> SEQ4 = { ' Hello ' :. 1, ' Good ' : 2, ' Boy ' :. 3, ' doiido ' :. 4 }
 56 is >>> Print  ' : ' .join (SEQ4)
 57 is  Boy: Good: doiido:
Hello 58    
59    
60  # combined directory 
61 is    
62 is >>> import os
63 >>> os.path.join('/hello/','good/boy/','doiido')
64 '/hello/good/boy/doiido'

 

Guess you like

Origin www.cnblogs.com/wutao1935/p/11328722.html