[英]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.