Python- conversion between strings, lists, ancestral

1. string into a list

= S ' erfwerg ' 
V = List (S)
 Print (V)   # output: [ 'e', 'r ', 'f', 'w', 'e', 'r', 'g']

2. string into ancestral

= S ' erfwerg ' 
V = tuple (S)
 Print (V)   # output :( 'e', 'r' , 'f', 'w', 'e', 'r', 'g')

3. List successful conversion string

# List only strings 
Li = [ ' QQQ ' , ' AAA ' , ' WWW ' , ' Eee ' , ' GGG ' ] 
S = '' .join (Li)
 Print (S)     # output: qqqaaawwweeeggg 

# List both figures, there are strings 
Li = [ ' QQQ ' , ' AAA ' , 555, ' Eee ' , ' GGG ' ,111]
s = '' 
For new_li in Li: 
    S = S + STR (new_li)
 Print (S)     # output: qqqaaa555eeeggg111

4. The list is converted into ancestral

= Li [ ' QQQ ' , ' AAA ' , 666, ' Eee ' , ' GGG ' ] 
V = tuple (Li)
 Print (V)      # output :( 'qqq', 'aaa' , 666, 'eee', 'ggg')

The list of tuples converted into

TU = ( ' QQQ ' , ' AAA ' , 666, ' Eee ' , ' GGG ' ) 
V = List (TU)
 Print (V)      # output: [ 'qqq', 'aaa ', 666, 'eee', 'ggg']

6. tuples into a string

# Ganso only string 
TU = ( ' QQQ ' , ' AAA ' , ' WWW ' , ' Eee ' , ' GGG ' ) 
V = '' .join (TU)
 Print (V)      # output: qqqaaawwweeeggg 

# Ganso in both figures, there are strings 
TU = ( ' QQQ ' , ' AAA ' , 1111, ' Eee ' , ' GGG ')
s=''
for new_tu in TU: 
    S = S + STR (new_tu)
 Print (S)       # output: qqqaaa1111eeeggg

 

Guess you like

Origin www.cnblogs.com/lijinping716/p/11297711.html