How to Get Rid of Brackets in Python Array


In Python, an array is a data type that can hold multiple values. You can visually recognize an array because it begins and ends in a bracket, such as [ 'green', 'blue', 'orange' ]. If the brackets are interfering with your display of a list of values, you can use the "join" command to display the array as a comma-separated list without the brackets.

  • Open a Python interpreter by typing "python" at the command line in Terminal on Mac OS X or Command Prompt on Windows.

  • Type the following to assign a variable to your existing array:

    colors = [ 'green', 'blue', 'orange' ]

  • Type the following to print your array as a list without brackets:

    print ', '.join(colors)

    This would print "green, blue, orange."

    Replace "colors" with the variable name assigned to your array.

    Replace the comma with another punctuation mark, such as a pipe ("|"), if you do not want to separate values with a comma.


Promoted By Zergnet


Related Searches

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!