Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python how to add quote to one of the element in a list?

values is a list looks like ['13020638659', '711799502', '4681912759', '07/21/2021']

I’d like to connect all of its elements to create a value_str look like this

(13020638659, 711799502, 4681912759, '07/21/2021')

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is what I do values_str = "(%s)" % (', '.join( values ))

But the output would be (13020638659, 711799502, 4681912759, 07/21/2021)

There are no quotes for the datatime string. How can I add quotes on it?

>Solution :

You need to use different code to format the date than the numbers, so you can add quotes around it.

values_str = f"({', '.join(values[:-1])}, '{values[-1]}')"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading