1

I saw this code somewhere, which writes:

print("{:-^16}".format("TEXT"))

The output is:

------TEXT------

I understand what the {} brackets do, but what does the -^16 mean? I tried searching online but couldn't find anything.

Georgy
  • 12,464
  • 7
  • 65
  • 73

1 Answers1

2

Braces are used as placeholders for the formatted string.

  • 16 is for the size of the string => 16 characters

  • ^ center aligns the result (within the available space)

You can find more information here: https://www.w3schools.com/python/ref_string_format.asp

CanciuCostin
  • 1,773
  • 1
  • 10
  • 25