简体   繁体   English

如何忽略字符串中的特定字符

[英]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?我怎样才能做到这一点?

You can use .replace() :您可以使用.replace()

For example,例如,

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

will output:将 output:

Z   Z

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM