日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

python 將兩個或者多個字符串進行拼接

作者:別出BUG求求了 更新時間: 2023-11-12 編程語言

概述:

Python中可以將兩個或多個字符串拼接起來,組成新的字符串

1. + 加法運算符

代碼:

str1 = 'hello'
print(str1+' '+'world!')

輸出:

hello world!

2. join()將列表轉化為字符串

代碼:

str2 = ['hello','world','everyone']
print('*'.join(str2))
print(' '.join(str2))

輸出:

hello*world*everyone

hello world everyone

3、format() 字符串中{}數量和format()參數個數必須一致

代碼:

str3 = '{} {}!'.format('hello','world')
print(str3)

輸出:

hello world!

4、%s 格式占位符

代碼:

str4 = '%s,%s!'%('hello','world')
print(str4)

輸出:

hello,world!

原文鏈接:https://blog.csdn.net/weixin_39589455/article/details/130506764

  • 上一篇:沒有了
  • 下一篇:沒有了
欄目分類
最近更新