Skip to content

Escape percentage symbol (%) in Python strings

Python uses the % symbol in strings as variable placeholder, so you need to escape it. You might expect it to be \%, but actually it’s %%.

print("A quarter of the pie is 25%%")
# Produces: "A quarter of the pie is 25%"


Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.