簡體   English   中英

如何刪除下面python代碼中的括號?

[英]How do I remove the parentheses in the python code below?

  x,y,z=1,2,3
print((x,y,z) * 2)
#the outpout is (1, 2, 3, 1, 2, 3)

我如何讓輸出不包括 ()

有沒有辦法單獨刪除逗號?

tuple解包為單獨的print參數,您將得到它以空格分隔:

print(*(x,y,z) * 2)

然后,您可以使用sep參數重新添加逗號:

print(*(x,y,z) * 2, sep=', ')

以下代碼:

x,y,z=1,2,3
print(*((x,y,z) * 2))

將不帶括號打印出來。

暫無
暫無

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

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