简体   繁体   中英

Convert multi-line text to string

I am new to Python so please excuse. I'm running some code that gives the following output-

Michael
John
Jack
Harry

I want to convert the output like

'Michael','John',Jack','Harry'
How should I go about doing this.

Thanks for all help.

If the output is a string you can convert it to list using split()

myString = 'Someone, something, somebody'
myList = myString.split(', ')

The newly created myList will look like this:

['Someone', 'something', 'somebody']

If you have many strings that you want to add to a list you can use append()

myList.append(myString)

Or you can just add them all together:

myList = [myString0, myString1]

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM