A Feature with an F-string that I Found out about by Accident
Vadim Kolobanov

Vadim Kolobanov @vadimkolobanov

About: Hi, I'm a python web developer, and I want to share my skills with people, as well as make web development popular in the world

Location:
Belarus
Joined:
Oct 22, 2021

A Feature with an F-string that I Found out about by Accident

Publish Date: Oct 27 '22
0 0

From author

You can find many interesting articles on my website, please visit it Happy Python Website

Look, here is the usual f-string

text = 'JUPI'
print(f'{text}') 
JUPI
Enter fullscreen mode Exit fullscreen mode

If I add to it

  • colon,
  • placeholder char,
  • and I will specify the required string length using the <
print(f'{text:-<15}') 
Enter fullscreen mode Exit fullscreen mode

Then the rest of the line that is not occupied by the text will be filled with the selected character:

JUPI-----------

If you specify the length of the string via >, then you can fill in the line on the left side:

print(f'{text:->15}') 
Enter fullscreen mode Exit fullscreen mode

-----------JUPI

Write in the comments how to fill in the line on both sides so that it turns out

-----JUPI------

Comments 0 total

    Add comment