2014-07-17 59 views

回答

1

你有兩個選擇:

如果在清單中的項目已經字符串:

list_of_strings = ['abc', 'def', 'ghi'] # give a list of strings 

new_string = "".join(list_of_strings) # join them into a new string 

如果在清單中的項目是不是所有的字符串,您可以必須把它們變成字符串優先:

list_of_nonstrings = [1.83, some_object, 4, 'abc'] # given a list of mixed types 

# construct new list of strings for join function 
list_of_strings = [str(thing) for thing in list_of_nonstrings] 

new_string = "".join(list_0f_strings) # join into new string, just like before 

現在您可以打印或操縱new_string h無論你需要什麼。

相關問題