[英]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)
how do I get the output to not include the ()我如何让输出不包括 ()
Is there a way, separately, to remove the commas?有没有办法单独删除逗号?
Unpack the tuple
as separate print
arguments, and you'll get it space-separated:将
tuple
解包为单独的print
参数,您将得到它以空格分隔:
print(*(x,y,z) * 2)
You can then add the commas back in with a sep
argument:然后,您可以使用
sep
参数重新添加逗号:
print(*(x,y,z) * 2, sep=', ')
the following code:以下代码:
x,y,z=1,2,3
print(*((x,y,z) * 2))
will print out without parentheses.将不带括号打印出来。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.