為什么在Python中使用string.join(list)而不是list.join(string)?

join() is a string method and while using it the separator string iterates over an arbitrary sequence, forming string representations of each of the elements, inserting itself between the elements.

join()是一個字符串方法,使用它時,分隔符字符串會在任意序列上迭代,從而形成每個元素的字符串表示形式,并在元素之間插入自己。

Concisely, it's because join and string.join() are both generic operations that work on any iterable and is a string method.

簡而言之,這是因為join和string.join()都是可在任何可迭代對象上使用的通用操作,并且是字符串方法。

Because it is a string method, the join() can work for the Unicode string as well as plain ASCII strings.

因為它是一個字符串方法,所以join()可以用于Unicode字符串以及普通ASCII字符串。

Example Usage of string.join(list)

示例string.join(list)的用法

-bash-4.2$ python3
Python 3.6.8 (default, Apr 25 2019, 21:02:35)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> test_string = "test"
>>> test_string.join("1234")
'1test2test3test4'
>>>

In the above example, the string "test" is joined with every character provided as a join argument.

在上面的示例中,字符串“ test”與作為連接參數提供的每個字符連接在一起。

-bash-4.2$ python3
Python 3.6.8 (default, Apr 25 2019, 21:02:35)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> test_string = "test"
>>> test_string.join("---")
'-test-test-'
>>>

翻譯自: https://www.includehelp.com/python/why-is-it-string-join-list-instead-of-list-join-string.aspx

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/542635.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/542635.shtml
英文地址,請注明出處:http://en.pswp.cn/news/542635.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

js的client、scroll、offset詳解與兼容性

clientWidth:可視區寬說明:樣式寬padding參考:js的client詳解 scrollTop : 滾動條滾動距離說明:chrome下他會以為滾動條是文檔元素的,所以需要做兼容:var scrollTop document.documentElement.scrollTop |…

88是python語言的整數類型_Python基礎數據類型題

Python基礎數據類型 題 考試時間:三個小時 滿分100分(80分以上包含80分及格) 1,簡述變量命名規范(3分)1.必須是字母,數字,下劃線的任意組合。 2.不能是數字開頭 3.不能是python中的關…

[轉載]使用awk進行數字計算,保留指定位小數

對于在Shell中進行數字的計算,其實方法有很多,但是常用的方法都有其弱點: 1、bc bc應該是最常用的Linux中計算器了,簡單方便,支持浮點。 [wangdongcentos715-node1 ~]$ echo 12 |bc 3 [wangdongcentos715-node1 ~]$ ec…

dcom配置_spring cloud 二代架構依賴組件 全配置放送

一 背景介紹先來看一下我們熟悉的第一代 spring cloud 的組件spring cloud 現在已經是一種標準了,各公司可以基于它的編程模型編寫自己的組件 ,比如Netflix、阿里巴巴都有自己的一套通過spring cloud 編程模型開發的分布式服務組件 。Spring Cloud 二代組…

olap 多維分析_OLAP(在線分析處理)| OLAP多維數據集和操作

olap 多維分析In the previous article of OLAP, we have seen various applications of OLAP, Various types of OLAP, advantages, and disadvantages of OLAP. In this article, we will learn about the, 在OLAP的上一篇文章中,我們了解了OLAP的各種應用&#x…

dede mysql語句_讓dede運行php代碼和mysql語句

一、dede運行php代碼舉例1:{dede:name runphpyes}$str "hello ";me $str;me . "world";{/dede:name}結果:hello world說明:"name"為任意定義的名字,me 表示當前的值,也就是要輸出最后…

每周一書-2016年8月28日到9月4日獲獎讀者公布

每周一書-2016年8月28日到9月4日獲獎讀者公布 上次送出的《Bootstrap基礎教程》,已經被幸運者收到了。我們先來回顧下《改善C程序代碼的125個建議》活動文章下的精彩留言。 這是一段高屋建瓴的評述,足見作者對C語言的了解和熱愛層度,當然也得…

c構造函數和析構函數_C ++構造函數和析構函數| 查找輸出程序| 套裝2

c構造函數和析構函數Program 1: 程序1&#xff1a; #include<iostream>using namespace std;class Sample{private:int X;int Y;public:Sample(int x, int y){X x;Y y;}void set(int x, int y){X x;Y y;}void print(){cout<<X<<" "<<Y&…

python map函數的作用_Python的map函數

map()是 Python 內置的高階函數&#xff0c;它接收一個函數 f 和一個 list&#xff0c;并通過把函數 f 依次作用在 list 的每個元素上&#xff0c;得到一個新的 list 并返回。 例如&#xff0c;對于list [1, 2, 3, 4, 5, 6, 7, 8, 9] 如果希望把list的每個元素都作平方&#xf…

idea java no sdk_java - intelliJ IDEA 13錯誤:請選擇Android SDK

java - intelliJ IDEA 13錯誤&#xff1a;請選擇Android SDK我已經在Error: Cannot find any configured Android SDK上安裝了intelliJ 12.1.2和Error: Cannot find any configured Android SDK。現在我使用intelliJ 13.0.1創建了一個空的android應用程序項目(也使用模擬器作為…

該怎樣在KeyShot中進行貼圖

2019獨角獸企業重金招聘Python工程師標準>>> 在渲染物體的時候&#xff0c;貼圖常常是不可缺少的部分&#xff0c;貼圖主要用于描述對象表面的物質形態&#xff0c;構造真實世界中自然物質表面的視覺表象。不同的貼圖能給人帶來不同的視覺感受&#xff0c;KeyShot3D…

python淘寶cookies搶購_Python實現淘寶秒殺聚劃算搶購自動提醒源碼

說明 本實例能夠監控聚劃算的搶購按鈕&#xff0c;在聚劃算整點聚的時間到達時發出提醒&#xff08;音頻文件自己定義位置&#xff09;并自動彈開頁面&#xff08;URL自己定義&#xff09;。 同時還可以通過命令行參數自定義刷新間隔時間&#xff08;默認0.1s&#xff09;和監控…

kadane算法_使用KADANE的算法求最大子陣列和

kadane算法What is a sub-array? 什么是子陣列&#xff1f; A sub-array is basically an arrays contiguous part. For example, if we have an array of integers [1,2,3] so the sub-arrays that we can form from the given array are [1], [2] , [3] , [1,2] , [2,3] , …

java汽車油耗計算_轉發一個手機油耗計算器 (java)

今天在一個汽車論壇上看見的&#xff0c;試了試&#xff0c;還真不錯。比以前那個Fuel Consumption 功能要強大,雖然都是JAVA軟件。小羅盤手機計算器是作者獨自產品策劃、美術設計、程序開發、測試發布的手機應用軟件&#xff0c;是為作者的一個朋友寫的&#xff0c;當然我們用…

6.dubbo常用的xml配置有哪些_【面試篇】必須掌握的Spring 常用注解

閱讀文本大概需要5分鐘。注解本身沒有功能的&#xff0c;就和 xml 一樣。注解和 xml 都是一種元數據&#xff0c;元數據即解釋數據的數據&#xff0c;這就是所謂配置。本文主要羅列 Spring|Spring MVC相關注解的簡介。Spring部分1、聲明bean的注解Component 組件&#xff0c;沒…

Linux的iptables常用配置范例(2)

iptables -F #清除所有規則 iptables -X #清除所有自定義規則 iptables -Z #各項計數歸零 iptables -P INPUT DROP #將input鏈默認規則設置為丟棄 iptables -P OUTPUT DROP #將output鏈默認規則設置為丟棄 iptables -A INPUT -i lo -j ACCEPT iptables -A OUTPUT -o lo …

aptitude 命令_C-命令行參數Aptitude問題與解答

aptitude 命令C programming Command Line Arguments Aptitude Questions and Answers: In this section you will find C Aptitude Questions and Answers on Command Line Arguments – Passing values with running programs, separate argument values, number of argument…

文件上傳java邏輯_Java?文件上傳?實例

import java.io.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;public class Upload {private String saveDir "."; // 要保存文件的路徑private String contentType ""; // 文檔類型private String charset "";…

matlab數值計算pdf_Gnuplot科學繪圖(九)——柵格以及方程數值解估算

Gnuplot科學繪圖系列內容Gnuplot科學繪圖(一)——從安裝到簡單函數繪圖(文末有彩蛋)Gnuplot科學繪圖(二)——坐標取值范圍及刻度(文末有彩蛋)Gnuplot科學繪圖(三)——點線風格Gnuplot科學繪圖(四)——多組數據繪圖Gnuplot科學繪圖(五)——輸出eps 圖片Gnuplot科學繪圖(六)——輸…

dda算法_計算機圖形學中的DDA(數字差分分析儀)算法

dda算法DDA(數字差分分析儀)算法 (DDA (Digital Differential Analyzer) Algorithm) In computer graphics, the DDA algorithm is the simplest algorithm among all other line generation algorithms. Here, the DDA is an abbreviation that stands for "Digital Diff…