How do I print a '%' sign using string formatting?

后端 未结 5 989
孤城傲影
孤城傲影 2020-12-30 20:32

I\'ve made a little script to calculator percent; however, I wish to actually include the \'%\' within the message printed...

Tried this at the start - didn\'t work.

5条回答
  •  盖世英雄少女心
    2020-12-30 21:34

    To print the % sign you need to 'escape' it with another % sign:

    percent = 12
    print "Percentage: %s %%\n" % percent  # Note the double % sign
    >>> Percentage: 12 %
    

提交回复
热议问题