'Python3 print formatting

I want to format the output from print function.

def main():
    print('1 2 3 4 5'*7)
    # Write code here 

main()

Required Output:
    1 2 3 4 5
    1 2 3 4 5
    1 2 3 4 5
    1 2 3 4 5
    1 2 3 4 5
    1 2 3 4 5
    1 2 3 4 5
Obtained Output:
    1 2 3 4 51 2 3 4 51 2 3 4 51 2 3 4 51 2 3 4 51 2 3 4 51 2 3 4 5

How do I make print function in Python3 to perform this job?



Solution 1:[1]

You can set the separator to be a linebreak.

print(*7*('1 2 3 4 5',), sep='\n')

Equivalently, you can add the linebreak at the end of the string and remove the end linebreak from print.

print(7*'1 2 3 4 5\n', end='')

Solution 2:[2]

Try this:

print('1 2 3 4 5\n'*7)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 General Grievance