[英]How do I remove parentheses and single quotation marks from my output?
拆分的結果是一個列表。 如果你想要 str 沒有周圍的空間,你應該使用strip
person = " xx "
what_he_said = " abc!"
print(f"{person.strip()}曾經說過,“{what_he_said.strip()}”")
.split()
person = " xx "
what_he_said = " abc!"
print(*person.split(),'曾經說過',*what_he_said.split())
split() function 將使用 [sep] 參數分隔數據,默認情況下它是空的,我假設你正在使用 split 刪除“[space-k]”,但請注意它總是返回一個單獨的參數列表
"hola como estas ".split(sep=" ")
將返回:
[hola, como, estas]
如果你真的需要使用 split() function,你可以通過索引獲取它的值。
例如
person = " xx "
what_he_said = " abc!"
print(f"{person.split()[0]}曾經說過,“{what_he_said.split()[0]}”")
將返回:
xx曾經說過,“abc!”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.