python 怎么將列表轉換成字符串


例子:

將列表 temp_list = ['h', 'e', 'l', 'l', 'o'] 轉換成字符串'hello',代碼如下:

temp_list = ['h', 'e', 'l', 'l', 'o']
result = ''.join(temp_list)
print(result)    # hello

字符串對象的方法join其描述如下:

大概意思是:s.join(iterable)是將括號內的迭代對象(如列表)使用s字符串作為鏈接將迭代對象中的元素拼接成一個字符串,返回該字符串。

    def join(self, iterable): # real signature unknown; restored from __doc__
        """
        S.join(iterable) -> str
        
        Return a string which is the concatenation of the strings in the
        iterable.  The separator between elements is S.
        """
        return ""
View Code

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM