How to Print the Values in a List without Spaces in Python?

Estimated read time 1 min read

You can use a loop to iterate over the elements in the list and use the end parameter of the print function to specify an empty string as the character to be printed at the end of each value. This will prevent any spaces from being inserted between the values. Here’s an example:

my_list = [1, 2, 3, 4, 5]
for element in my_list:
    print(element, end="")

Output:

12345

In this example, the end parameter of the print function is set to an empty string (""), which replaces the default newline character that is printed at the end of each line with nothing. This causes each element to be printed immediately after the previous one, without any spaces or newlines in between.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply