-2

Like %i or %yellow? I'm not looking for it as an operator like 67%3. But like this:

print("pink is %i" %grade)

what does the above code mean?

Ismael Padilla
  • 5,246
  • 4
  • 23
  • 35
  • it is used to format code - to put value from `grade` in place of `%i` - you should first run code to see it - and ask later. BTW: [pyformat.info](https://pyformat.info/) – furas Jan 12 '20 at 00:18
  • 1
    It's the wrong way to format a string. This is a very old style of string interpolation and should be left in the past in favor of more current approaches like `str.format` (`"pink is {:d}".format(grade)`) or its shortcut mechanism, the f-string (`f"pink is {grade:d}"`) – Adam Smith Jan 12 '20 at 02:30

1 Answers1

1

It is used to format strings (you can read about string formatting in the string docs, also mentioned in Input and Output - old string formatting).

print("pink is %i" %10) 

Output

pink is 10

Ismael Padilla
  • 5,246
  • 4
  • 23
  • 35