Usually when Python outputs a list string, it will automatically add quotation marks and brackets.
For example (recommended learning: Python video tutorial)
str=['hello','world'] >>> str ['hello', 'world']
Method 1
You can use the join method:
>>> print " ".join(str) hello world
Among them: The Python join() method is used to connect the elements in the sequence with the specified characters to generate a new string.
For example:
str = "-" seq = ("a", "b", "c") print str.join( seq )
Output result:
a-b-c
Method 2: If the list stores numbers, then: just convert it to int. Because the original storage is string type
str=['1', '2', '3'] for i in str: int(i) print(i)
For more Python related technical articles, please visit the Python Tutorial column to learn!
The above is the detailed content of How to remove square brackets from data in python. For more information, please follow other related articles on the PHP Chinese website!