'Python Print List new line and tabbed

I have a list with a variable number of integers in it (dependent on user input). I am wanting to print this list of values, each one on a new line and tabbed in.

My current code is:

print("List values are: ")
print(*test_list, sep = "\n\t")

The problem with this is that the first entry isn't tabbed in so the output is:

List values are: 
1
     2
     3

how do I ensure the first value tab's in as well?



Solution 1:[1]

The sep argument adds the new line and tab between the values of the list; that's why you are getting a behavior like this.

What you could do is add an end argument to the first print statement.

print("List values are: ",end="\n\t")
print(*test_list,sep = "\n\t")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SAMYAK JAIN