簡體   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