日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Python字符串| join()方法与示例

發布時間:2023/12/1 python 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python字符串| join()方法与示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

join() is an in-built method in Python and it is used to join elements of the list, string etc with the given str separator.

join()是Python中的一種內置方法,用于通過給定的str分隔符連接列表,字符串等元素。

Note: Method is called with the separator and as arguments elements are provided, then the final (returned) string is a joined string by the separator string.

注意:方法是使用分隔符調用的,并提供了arguments元素,然后最后一個(返回的)字符串是分隔符字符串連接的字符串。

Syntax:

句法:

String.join(iterable)

Example 1: Joining string with hyphen ('-') character

示例1:使用連字符('-')連接字符串

# s as separator string s = "-" # str as sequence of strings str = ("Hello", "World", "How are?")# join and print the string print (s.join(str))

Output

輸出量

Hello-World-How are?

Example 2: Joining string with spaces, a student detail is provided as string sequences

示例2:將字符串與空格連接,將學生詳細信息作為字符串序列提供

# s as separator string (contains - space) s = " "# a student details first_name = "Amit" second_name = "Shukla" age = "21" branch = "B.Tech"# creating string sequences str = (first_name, second_name, age, branch)# value of str before joining print "str before join..." print (str)# join and print the string print "str after join..." print (s.join(str))

Output

輸出量

str before join...('Amit', 'Shukla', '21', 'B.Tech')str after join...Amit Shukla 21 B.Tech

翻譯自: https://www.includehelp.com/python/string-join-method-with-example.aspx

總結

以上是生活随笔為你收集整理的Python字符串| join()方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。