Intellipaat 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 Feb 7, 2021 in Python by ashely (50.2k points)
0 votes
1 answer

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...