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