Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
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

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...