Code
for i in range(3):
s = ('test',i)
print (s)
('test', 0)
('test', 1)
('test', 2)`
is there any way to print like below
(test, 0)
(test, 1)
(test, 2)
Basically I need to print without ''
You would need to print the result as a formatted string, including your ()
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])
This output's
test 0
test 1
test 2
Try the code below,
for i in range(3):
print ('(test, {})'.format(i))
Output
(test, 0)
(test, 1)
(test, 2)
this code remove the single quotes
for i in range(3):
s = ('test',i)
print ('('+str(s[0])+','+str(s[1])+')')
Is it important to retain the parentheses and comma? If not, simply add 1 *
character to your print statement to unpack the tuple
for i in range(3):
s = ('test',i)
print(*s)
output:
test 0
test 1
test 2
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.