How to Print a Horizontal Line in Python

How to Print a Horizontal Line in Python

Glasshost
2 min readApr 28, 2023

Printing a horizontal line in Python is a common task that can be accomplished with just a few lines of code. Follow the steps below to learn how to do it.

Step 1: Choose a Character

The first step is to choose the character that you want to use to create the horizontal line. This can be any character, such as a hyphen (-), an asterisk (*), or a pound sign (#).

Step 2: Determine the Length of the Line

The next step is to determine the length of the line that you want to print. This can be done by specifying the number of times that you want the chosen character to be printed.

Step 3: Print the Line

With the character and length determined, you can now print the horizontal line using the `print()` function. In the parentheses, you will include the chosen character multiplied by the desired length.

Here’s an example code snippet that demonstrates how to print a horizontal line using the hyphen (-) character and a length of 10:

print("-" * 10)

This will output the following line:

----------

Conclusion

Printing a horizontal line in Python is a simple task that can be accomplished using the `print()` function and a chosen character. By following the steps outlined in this guide, you can easily create horizontal lines of varying lengths and characters in your Python code.

--

--

Glasshost

Hey, I am Shivam Kumar, Founder of GlassHost.tech. We offer some very competitive hosting solutions and solve coding issues/problems. Visit Glasshost.tech now.