Home > Back-end >  Python Print List new line and tabbed
Python Print List new line and tabbed

Time:05-03

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?

CodePudding user response:

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")
  • Related