I have a tuple:
tuple = ('one', ('two', 'three'))
I want to print remove the '
from this tuple so I can print it as (one, (two, three))
.
I have tried this
tuple = str(tuple)
print tuple.strip(')
But I get this error:
print tuple.strip(')
^
SyntaxError: EOL while scanning string literal
How can I turn my tuple into the desired string?
t = ('one', ('two', 'three'))
t2 = str(t)
print(t2.replace("'",""))
It's considered bad practice to use keywords like tuple
as variable names, you might run into trouble with that.
You can print with replace:
print(str(tuple).replace("'", ''))
output
(one, (two, three))
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.