Categories
Python Answers

How to selectively escape percent (%) in Python strings?

Spread the love

Sometimes, we want to selectively escape percent (%) in Python strings.

In this article, we’ll look at how to selectively escape percent (%) in Python strings.

How to selectively escape percent (%) in Python strings?

To selectively escape percent (%) in Python strings, we put % before the % sign to escape it.

For instance, we write

elective_escape = "Print percent %% in sentence and not %s" % test

to escape the first % with %%.

Then we print the string, one % will be printed.

Conclusion

To selectively escape percent (%) in Python strings, we put % before the % sign to escape it.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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