0 votes
1 view
in Python by (47.8k 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 (107k 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
asked Jul 26, 2019 in Java by Shubham (3.9k points)
0 votes
1 answer
asked Nov 2 in Python by Sudhir_1997 (46.9k points)
0 votes
1 answer
asked Nov 24 in Python by ashely (44.6k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...