How to replace a string in a function with another string in Python?

前端 未结 4 1102
暗喜
暗喜 2020-12-21 07:23

I want to do this:

>>> special = \'x\'
>>> random_function(\'Hello how are you\')
\'xxxxx xxx xxx xxx\'

I basically want

4条回答
  •  醉梦人生
    2020-12-21 07:41

    This can be easily done with regex:

    >>> re.sub('[A-Za-z]', 'x', 'Hello how are you')
    'xxxxx xxx xxx xxx'
    

提交回复
热议问题