Skip to content
Advertisement

Convert a tuple into a String and replace square brackets with round ones Python

I am trying to replace square brackets in a tuple with round brackets which I had converted into a String and then tried to replace. Below is the code I am trying.

JavaScript

But this is printing [‘ABCXYZ-I’, ‘ABCXYZ-I’, ‘ABCXYZ-I’]. I want to print (‘ABCXYZ-I’, ‘ABCXYZ-I’, ‘ABCXYZ-I’). Am I missing something here?

Advertisement

Answer

table_tpl.replace('[','(')

.replace returns the new string, but you are just throwing the return value away. You will have to do something like

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement