Fiya
Fiya

Reputation: 9

How to ignore specific characters in string

I have these variables

m1 = 'ZZZZZ'

m2 = 'Z___Z'

m3 = 'ZZZZZ'

that represent a maze. When I print these strings out, I want it to ignore the underscores and replace them with spaces. How can I achieve this?

Upvotes: 0

Views: 123

Answers (1)

BrokenBenchmark
BrokenBenchmark

Reputation: 19242

You can use .replace():

For example,

'Z___Z'.replace('_', ' ')

will output:

Z   Z

Upvotes: 2

Related Questions