Aaron
Aaron

Reputation: 41

Dynamically print spaces/tabs in python

have a scenario

df has 5 rows

for i in range(len(df)):
    print ("\t", i, "Time")

need the output to look like

 0 Time
      1 Time
           2 Time
                3 Time
                     4 Time

How do we make python add the tabs depending on the counter value? Is there a way to do this?

Upvotes: 0

Views: 926

Answers (2)

tersrth
tersrth

Reputation: 889

Simple change:

for i in range(len(df)):
    print ("\t"*i, i, "Time")

Upvotes: 1

Coder1238
Coder1238

Reputation: 36

You could try multiplying of string which would give i no of tabs:

for i in range(len(df)):
    print ("\t"*i, i, "Time")

Upvotes: 1

Related Questions