Python join()方法

2019-06-02 17:12:16python

描述

Python join() 方法用於將序列中的元素以指定的字符鏈接生成一個新的字符串。blog

語法

join()方法語法:字符串

str.join(sequence)

參數

  • sequence -- 要鏈接的元素序列。

返回值

返回經過指定字符鏈接序列中元素後生成的新字符串。class

實例

如下實例展現了join()的使用方法:coding

#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
str = "-";
seq = ("a", "b", "c"); # 字符串序列
print str.join( seq );

以上實例輸出結果以下:語法

a-b-c
相關文章
相關標籤/搜索