Home > database >  How to insert extra elemet before an iteration without affecting the distance between existing print
How to insert extra elemet before an iteration without affecting the distance between existing print

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