繁体   English   中英

如何从输出中删除 '

[英]How to remove ' from the output

代码

for i in range(3):
    s = ('test',i)
    print (s)
('test', 0)
('test', 1)
('test', 2)`

有什么方法可以打印如下

(test, 0)
(test, 1)
(test, 2)

基本上我需要在没有''情况下打印

您需要将结果打印为格式化字符串,包括您的()

for i in range(3):
    s = ('test',i)
    print (f"({s[0]}, {s[1]})")

#(test, 0)
#(test, 1)
#(test, 2)
for i in range(3):
    s = ('test',i)
    print (s[0], s[1])

这个输出的

test 0
test 1
test 2

试试下面的代码,

for i in range(3):
    print ('(test, {})'.format(i))

输出

(test, 0)
(test, 1)
(test, 2)

此代码删除单引号

 for i in range(3):
        s = ('test',i)
        print ('('+str(s[0])+','+str(s[1])+')')

保留括号和逗号重要吗? 如果没有,只需在打印语句中添加 1 *字符即可解压元组

for i in range(3):
    s = ('test',i)
    print(*s)

输出:

test 0
test 1
test 2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM