0
for i in range(21):
        sys.stdout.write('\r')
        sys.stdout.write("[%-20s] %a%%" % ('='*i, 5*i))
        time.sleep(0.25)

I need help understanding line 3. I would appreciate help. I know what this code does, but I don't know how. For example, I don't understand what the % does.

Ineedhelp
  • 1
  • 3
  • 1
    Hi there, welcome to the site. This question looks like an exact match, does it answer your question? https://stackoverflow.com/q/1238306/3141234 – Alexander Jun 09 '21 at 01:30
  • The `%` is part of a "format specifier" - https://realpython.com/python-input-output/#the-string-modulo-operator -- `%-20s` says to "left-align a string 20 characters wide". – user2864740 Jun 09 '21 at 01:31
  • What does the letters mean in the code? – Ineedhelp Jun 09 '21 at 01:34
  • The realpython article or the stackoverflow? – Ineedhelp Jun 09 '21 at 01:35
  • The link in my comment. Here is a link to the Python ref. docs as well: https://docs.python.org/3/library/stdtypes.html?highlight=printf#old-string-formatting Anyway, `%-20s` is read by `%/printf` as `%[flags=-][width=20][conversion=s]`, `%a` is read as `%[conversion=a]` and `%%` escapes the `%` so it has no meaning in the format (it will output a single `%`). – user2864740 Jun 09 '21 at 01:39

0 Answers0