-1

In particular, this is over my head:

print(f"foo: {foo:>7f}, bar: {bar:>5d}")

I can imagine that f indicates float and d indicates integer but I don't really understand what the >7f and >5d do.

Note that I understand what

print(f"foo: {foo}, bar: {bar}")

does.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
Essam
  • 395
  • 3
  • 15

1 Answers1

4

It means that the resulting string from {foo:>7f} should at least be of width 7, meaning that if it were 4 characters/digits long, then spaces would be appended to its left.

>>> foo = 1234
>>> bar = 100
>>> f"foo: {foo:>7d}, bar: {bar:>5d}"
'foo:    1234, bar:   100'

Note the spaces are before each number.

>>> f"foo: {foo:>4d}, bar: {bar:>5d}"
'foo: 1234, bar:   100'

Notice how the first number isn't affected because it has width of 4.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
saedx1
  • 984
  • 6
  • 20