Sometimes, while working with displaying the contents of list, the square brackets, both opening and closing are undesired. For this when we need to print whole list without accessing the elements for loops, we require a method to perform this. Let’s discuss a shorthand by which this task can be performed.
Method : Using
str() + list slicing
The shorthand that can be applied, without having need to access each element of list is to convert the entire list to string and then strip the initial and last character of list using list slicing. This won’t work if list contains a string. In that case, each element can be joined using
join(), as discussed in many other articles.
The original list is : [5, 6, 8, 9, 10, 21] List after removing square brackets : 5, 6, 8, 9, 10, 21
- Python | Remove all values from a list present in other list
- Python - Remove empty List from List
- Python list remove()
- Python - Remove first element of list
- Python - Remove Key from Dictionary List
- Python | Remove None values from list
- Python Remove Duplicates from a List
- Python - Remove Units from Value List
- Python | Remove given element from the list
- Python | Remove last K elements of list
- Python | Remove all strings from a list of tuples
- Python | Remove repeated sublists from given list
- Python | Remove consecutive duplicates from list
- Python | Remove given element from list of lists
- Python | Remove all digits from a list of strings
- Remove multiple elements from a list in Python
- Python | Remove Kth character from strings list
- Python | Remove last character in list of strings
- Python - Remove rear element from list
- Python | Remove particular element from tuple list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.