Home > Net >  How to insert extra element before an iteration without affecting the distance between existing prin
How to insert extra element before an iteration without affecting the distance between existing prin

Time:09-25

Input:

a = ['x', 'y', 'z']

Syntax:

for i in a:
    print(f'{i:<14}', end = '')

Current output:

x             y             z

Expected output

Title                                   x             y             z   

CodePudding user response:

Print "Title" before the loop:

print("Title", end=' ' * 25)
for i in a:
    print(f'{i:<14}', end = '')

Output:

Title                         x             y             z       
  • Related