How to remove square brackets from data in python

(*-*)浩
Release: 2019-07-09 10:31:06
Original
11327 people have browsed it

Usually when Python outputs a list string, it will automatically add quotation marks and brackets.

How to remove square brackets from data in python

For example (recommended learning: Python video tutorial)

str=['hello','world']
>>> str
['hello', 'world']
Copy after login

Method 1

You can use the join method:

>>> print " ".join(str)
hello world
Copy after login

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 )
Copy after login

Output result:

a-b-c
Copy after login

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)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template