How to Print a Horizontal Line in Python?

Estimated read time 1 min read

You can print a horizontal line in Python using a loop and a print statement. Here is an example code snippet:

# Print a horizontal line of length 10
for i in range(10):
    print("-", end="")

In the above code, we use a for loop to iterate 10 times, and within each iteration, we print a dash symbol - using the print() function. The end parameter is set to an empty string "" to prevent the print() function from adding a newline after each dash.

You can modify the length of the horizontal line by changing the range value of the for loop. For example, if you want a line of length 20, you can change the loop to for i in range(20):.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply