I am getting in a list format ['Test']
this i need to covert it like ('Test')
I tried:
test = '(' +test[0]+ ')'
Output:
'(Test)'
And I tried:
test = "('"+"', '".join(test)+"')"
I got result in like:
"('Test')"
Remove double quotes in python. I need to get output like ('Test')
. But now am getting like this ``
Thanks in Advance
Here you go:
string = '''"('test')"'''
print(string.strip('"'))
>>> ('test')
Using strip
you can remove any characters from a string.
I believe this is what you want:
str_list = ['Test1', 'Test2', 'Test3']
# desired output: ('Test1', 'Test2', 'Test3')
# print(tuple(str_list))
print(str(tuple(str_list)).rstrip(',)') + ')')
OUTPUT:
('Test1', 'Test2', 'Test3')
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.