Home > Net >  Join() method and tuples in Python
Join() method and tuples in Python

Time:10-30

I have one problem, here is my code

test = (('BoringDAO',199.09,0.48),('Santiment Network Token',0.66,0.25))
for data in test:
    print('         '.join([str(item) for item in data]))

When I print it, this is what I got :

BoringDAO         199.09         0.48
Santiment Network Token         0.66         0.25

As you see, it's not align and I would like to find a solution to align everything like this :

BoringDAO                       199.09         0.48
Santiment Network Token         0.66           0.25

Does anyone has an idea ? I do not have only two things to print, I have about 30 things to print but I would like everything to be aligned. Thank you very much for the help

CodePudding user response:

You could leverage fstring formatting.

test = (('BoringDAO',199.09,0.48),('Santiment Network Token',0.66,0.25))

for x in test:
    print(f'{x[0]:30}{x[1]:10}{x[2]:10}')

Output

BoringDAO                         199.09      0.48
Santiment Network Token             0.66      0.25
  • Related