Print a List as a String in Python

  • Post category:List

Printing a list as a string is a common task in Python programming. In this blog post, we’ll explore different code examples that demonstrate how to convert a list to a string and display it efficiently.

Example 1:

fruits = ['apple', 'banana', 'kiwi']
fruits_string = ', '.join(fruits)
print(fruits_string)

Output: apple, banana, kiwi

Example 2:

numbers = [1, 2, 3, 4, 5]
numbers_string = ''.join(str(num) for num in numbers)
print(numbers_string)

Output: 12345