Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I have the following code

test = "have it break."

selectiveEscape = "Print percent % in sentence and not %s" % test print(selectiveEscape)

I would like to get the output:

Print percent % in sentence and not have it break.

What actually happens:

selectiveEscape = "Use percent % in sentence and not %s" % test

TypeError: %d format: a number is required, not str

1 Answer

0 votes
by (106k points)

To selectively escape per cent (%) in Python strings you can use the following piece of code:-

test = "have it break."

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

print(selectiveEscape)

image

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 26, 2019 in Java by Shubham (3.9k points)

Browse Categories

...