繁体   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