Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
例如,我如何将 45 转为转(45)?或者通常在python中将AnyValue反转为reverse(AnyValue)?
用户输入可以是:
reverse 45
然后输出可能是:
reverse(45)
您可以使用正则表达式在数字周围添加括号:
import re s = "reverse 45" output = re.sub(r'reverse (\d+)', r'reverse(\1)', s)
python 3.2 a = reverse 45 a.replace(" ","(") + ")"