can anyone help me to explain pyhton syntax

Question:

def print_formatted(number):
    # your code goes here
    padding = len(bin(number)[2:])
    
    for i in range(1, number+1):
        print(f"{i: >{padding}} {oct(i)[2:]: >{padding}} "
              f"{hex(i)[2:].upper(): >{padding}} {bin(i)[2:]: >{padding}}")

I’m trying to debug above code i know the output and working of the code but i couldn’t understand is that what

": >"

doing in f string formatting

can anyone help me to explain ": > " this syntax

Asked By: Gaurav D. Lohar

||

Answers:

It is used for padding:

print(f"{8:<3}")
  8  # note three spaces
# make them visible:
print(f"{8:.<3}")
..8

In the last example the . is used instead of spaces.

Answered By: 3dSpatialUser
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.