Print List In Python

There are many ways to print a list in python. We will tell you the best and easy ways by which you can print it and lots of people have questions that how to remove brackets and commas from a list in python so we will define how to remove brackets from a list as well.

Sometimes it gets IndexError when we try to access the list by the wrong index.

First, we will see about the list in python.

What is list in python?

Python is an open-source platform for developers, it offers a lot of different features but at the same time, it is very flexible. You may have heard the term list when talking to someone in the programming world and wondered what it was. In Python, a list is an ordered collection of objects that are enclosed in square brackets each item separated by a comma. Every item in the list must be of the same type.

Best & easy methods to print list in python

Using Join Method – join()

Join method used for converting & combining data into string whether it’s tuple, list, or string. You have to use any separator with join like ‘-‘.join(data). otherwise, there will not be any space or separator between our return data.

Example

languages = ["Python","PHP","Java","Javascript"]

print(' '.join(languages)) // empty space is seperator here

Output

Python PHP Java Javascript

Using For Loop

For loop is used to repeat some code for the number of times that we define.

Example

a = [11, 22, 33, 44, 55]
  
for x in range(len(a)):
    print a[x]

Output

11 22 33 44 55

Using * Symbol

Example

myList = ['Python', 'By', 'PHP ERROR CODE', 9, 8, 7]

print(*myList, sep=' - ')

Output

Python - By - PHP ERROR CODE - 9 - 8 - 7

Conclusion

In this article, we defined how can we print a python list and remove its brackets.

Leave a Comment