
Dylan L. answered 10/08/21
Python Programmer and Tutor
The curly braces {} mark tell format where to insert the variable inside of the string. The code to the right of the colon affects how it will be formatted. In this case we have >3, which tells Python to create a padded area of three characters with the variable aligned to the right. So for example, if our variable is the letter 'A', the output will look like this:
Take special note of the spaces before the number. Now lets compare it to the same formatting with the letters 'am' :
Notice how the string is exactly the same length. There is just one fewer spaces. That is because the spaces are simply a "filler" for any part of the padded area that isn't used to print the actual variable. If we change the formatting code to "{:>6}", then this is what will print out:
You can also align text to the left using <. For instance:
And finally you can center your text using ^: