簡體   English   中英

在 Pyton 的字符串中添加引號

[英]Add Quotation Mark in a string in Pyton

如何在 Python 中將'hello', 'how', 'are', 'you' 'hello how are you'改為'hello', 'how', 'are', 'you' 我試過使用split(',') ,它沒有得到我想要的結果。

text = "'hello how are you'"
print("', '".join(text.split()))

輸出:

'hello', 'how', 'are', 'you'

解釋:

  • A.split() :用空格分割字符串A
  • A.join(B) :通過字符串A連接B (字符串數組)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM