Home > Software engineering >  How do I add a horizontal line in python?
How do I add a horizontal line in python?

Time:01-30

This is my example:

Input:

print("There will be a line below")
#line goes here
print("This is a line above")

Output:

There will be a line below
---------------------------------------------------------------------------------------
There is a line above

Other than actually having to manually type the line, is there a way I can just add a horizontal divider line in the middle of the console?

CodePudding user response:

You are able to multiply a string.

print(50 * "_")

Maybe that will help you out!

Cheers!

CodePudding user response:

You can set the parameter end in the print function to a newline followed by a bunch of dashes:

print('hello world', end='\n' '-'*80)

Outputs:

hello world
--------------------------------------------------------------------------------

To make this a little less ugly you could store the line in a variable and pass it to the print function when you want to use it.

line = '\n' '-'*80
print('hello world', end=line)
  •  Tags:  
  • Related