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

后端 未结 5 952
孤城傲影
孤城傲影 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:12

    Or use format() function, which is more elegant.

    percent = 12
    print "Percentage: {}%".format(percent)
    

    4 years later edit

    Now In Python3x print() requires parenthesis.

    percent = 12
    print ("Percentage: {}%".format(percent))
    

提交回复
热议问题