Python | Ways to print list without quotes
Whenever we print list in Python, we generally use str(list) because of which we have single quotes in the output list. Suppose if the problem requires to print solution without quotes. Let’s see some ways to print list without quotes.
Method #1: Using map()
# Python code to demonstrate # printing list in a proper way # Initialising list ini_list = ['a', 'b', 'c', 'd'] # Printing initial list with str print ("List with str", str(ini_list)) # Printing list using map print ("List in proper method", '[%s]' % ', '.join(map(str, ini_list))) |
chevron_right
filter_none
Output:
List with str ['a', 'b', 'c', 'd'] List in proper method [a, b, c, d]
Method #2: Using sep Method
# Python code to demonstrate # printing list in proper way # Initialising list ini_list = ['a', 'b', 'c', 'd'] # Printing initial list with str print ("List with str", str(ini_list)) # Printing list using sep Method print (*ini_list, sep =', ') |
chevron_right
filter_none
Output:
List with str ['a', 'b', 'c', 'd'] a, b, c, d
Method #3: Using .format()
# Python code to demonstrate # printing list in proper way # Initialising list ini_list = ['a', 'b', 'c', 'd'] # Printing initial list with str print ("List with str", str(ini_list)) # Printing list using .format() print ("Printing list without quotes", ("[{0}]".format( ', '.join(map(str, ini_list))))) |
chevron_right
filter_none
Output:
List with str ['a', 'b', 'c', 'd'] Printing list without quotes [a, b, c, d]
Method #4: Using translate Method
# Python code to demonstrate # printing list in proper way # Initialising list ini_list = ['a', 'b', 'c', 'd'] # Printing initial list with str print ("List with str", str(ini_list)) translation = {39: None} # Printing list using translate Method print ("Printing list without quotes", str(ini_list).translate(translation)) |
chevron_right
filter_none
Output:
List with str ['a', 'b', 'c', 'd'] Printing list without quotes [a, b, c, d]
Recommended Posts:
- Python | Ways to sum list of lists and return sum list
- Single and Double Quotes | Python
- Python | Ways to Convert a 3D list into a 2D list
- Python | Avoiding quotes while printing strings
- Print lists in Python (4 Different Ways)
- Ways to print escape characters in Python
- Python | Ways to flatten a 2D list
- Python | Ways to Spilt the list by some value
- Extending a list in Python (5 different ways)
- Python | Ways to shuffle a list
- Python | Ways to rotate a list
- Different ways to clear a list in Python
- Python | Ways to remove duplicates from list
- Python | Ways to remove particular list element
- Python | Ways to initialize list with alphabets
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.



