DEV Community

Cover image for Creating Divider Lines in Python
Luca Liu
Luca Liu

Posted on β€’ Edited on

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

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (2)

Collapse
 
sreno77 profile image
Scott Reno β€’

You might consider using f-strings instead of format.

Collapse
 
luca1iu profile image
Luca Liu β€’

how to use f-strings to print the same divider lineπŸ˜€

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay