Home  >  Article  >  Backend Development  >  How to remove [] from a list in python

How to remove [] from a list in python

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-06-24 17:21:5322067browse

How to remove [] from a list in python

#How to remove [] from a list in python? Let me explain the specific method below:

LIST = ['Python','problem','whatever']
print(LIST)

Running results:

[Python, problem, whatever]

Related recommendations: "Python Video Tutorial"

If you want to start from Removing the square brackets from the output converts it to a string instead of printing the list directly:

>>> LIST = ['Python','php','java']
>>> print(", ".join(LIST))
Python, php, java

If the elements in the list are not strings, you can use repr (if you want to quote strings) or str (if not) convert them to strings like this:

>>> LIST = [1, "foo", 3.5, { "hello": "bye" }]
>>> print(", ".join(repr(e) for e in LIST))
1, 'foo', 3.5, {'hello': 'bye'}

The above is the detailed content of How to remove [] from a list in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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