Creating Divider Lines in Python

luca1iu

Luca Liu

Posted on January 23, 2024

Creating Divider Lines in Python

Basic Divider Line

The simplest way to create a divider line in Python is to use the format method with the ^ option to center align a character within a specified width. Let's see an example:

print("{:=^50s}".format("Split Line"))
Enter fullscreen mode Exit fullscreen mode

The output will look like this:

====================Split Line====================
Enter fullscreen mode Exit fullscreen mode

Customizing Divider Lines

You can easily customize the appearance of the divider line by changing the fill character and adjusting the width.

print("{:-^50s}".format("Split Line"))
print("{:*^50s}".format("Split Line"))
print("{:'^50s}".format("Split Line"))
Enter fullscreen mode Exit fullscreen mode

The output for these examples will be:

--------------------Split Line--------------------
********************Split Line********************
''''''''''''''''''''Split Line''''''''''''''''''''
Enter fullscreen mode Exit fullscreen mode

Explore more

Thank you for taking the time to explore data-related insights with me. I appreciate your engagement.

🚀 Connect with me on LinkedIn

🎃 Connect with me on X

🌍 Connect with me on Instagram

💖 💪 🙅 🚩
luca1iu
Luca Liu

Posted on January 23, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related