Software Sec Asked:2022-07-22 23:51:23 +0800 CST2022-07-22 23:51:23 +0800 CST 2022-07-22 23:51:23 +0800 CST 蟒蛇 | 字符替换 772 大家好,假设我有一个字符串 打印('你好世界') 如何在不更改内容的情况下替换这一行中的 print('') python str 1 个回答 Voted Best Answer Bol4onok 2022-07-23T00:11:07+08:002022-07-23T00:11:07+08:00 好吧,实现选项之一: import re pattern = r'print\(([^\)]*)\)' repl = r'display[\1]' string = 'print(\'Hello world\')' answer = re.sub(pattern, repl, string) print(answer) 结论 display['Hello world']
好吧,实现选项之一:
结论