精品伊人久久大香线蕉,开心久久婷婷综合中文字幕,杏田冲梨,人妻无码aⅴ不卡中文字幕

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
python技巧 - 連接字符串的 6 種方法
userphoto

2022.06.18 福建

關注

本文匯集了連接字符串的 6 種常用方法,介紹如下:

使用“+”運算符連接字符串

s = 'String' + ' Concatenation' print(s)# String Concatenation

或者,

s1 = 'String's2 = s1 + ' Concatenation'print(s2)# String Concatenation

使用“+=”運算符連接字符串

和使用使用“+”運算符類似,可以用來把多個字符串連接成為一個字符串,

s = 'String's += ' Concatenation'print(s)# String Concatenation

使用join()方法連接字符串

s1 = 'String's2 = 'Concatenation's3 = ''.join([s1, s2])print(s3)# StringConcatenation

使用 join() 方法連接字符串時,也可以指定分隔符,

s1 = 'String's2 = 'Concatenation's3 = '_ '.join([s1, s2])print(s3)#String_Concatenation

在上面的例子中,用“_”作為分隔符,下面的例子中使用“,”逗號作為分隔符,

s1, s2, s3 = 'Python', 'String', 'Concatenation's = ','.join([s1, s2, s3])print(s)#Python,String,Concatenation

使用格式符 % 連接字符串

s1, s2, s3 = 'Python', 'String', 'Concatenation's = '%s %s %s' % (s1, s2, s3)print(s)# Python String Concatenation

使用format() 方法連接字符串

s1, s2, s3 = 'Python', 'String', 'Concatenation's = '{} {} {}'.format(s1, s2, s3)print(s)# Python String Concatenation

使用 f-strings 形式連接字符串

s1, s2, s3 = 'Python', 'String', 'Concatenation's = f'{s1} {s2} {s3}'print(s)# Python String Concatenation
本站僅提供存儲服務,所有內容均由用戶發布,如發現有害或侵權內容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Python 字符串連接方法:一文就夠了
python之字符串查找與替換
實現更好編碼的 30 個神奇的 Python 技巧
從字符串和列表創建元組-Python
關于Python3.9,你不可不知的4個新特性
python中index怎么用
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯系客服!

聯系客服

主站蜘蛛池模板: 洪雅县| 新和县| 集安市| 武川县| 孝昌县| 丁青县| 大厂| 紫金县| 称多县| 芮城县| 平安县| 武乡县| 大埔县| 莎车县| 大同县| 黄龙县| 安顺市| 台东县| 寿宁县| 汨罗市| 青海省| 安远县| 峨山| 罗江县| 师宗县| 桓台县| 祁连县| 雷州市| 诸城市| 车致| 遂宁市| 新丰县| 墨竹工卡县| 文山县| 顺平县| 揭东县| 惠水县| 靖安县| 陆良县| 百色市| 门头沟区|