close

How do I print a ‘%’ sign using string formatting?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How do I print a ‘%’ sign using string formatting in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How do I print a ‘%’ sign using string formatting?

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

    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 %

  2. print a '%' sign using string formatting

    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 %

Method 1

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 %

Method 2

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))

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read