Python中区分大小写的字符串替换 [英] case sensitive string replacement in Python
本文介绍了Python中区分大小写的字符串替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要以区分大小写的方式替换字符串.例如
<前>abc -> defABC -> 定义aBc -> dEfabC -> deF我可以用 Python 做什么?
解决方案
from string import maketrans"abc".translate(maketrans("abcABC", "defDEF"))
I need to replace a string in case sensitive way. For example
abc -> def Abc -> Def aBc -> dEf abC -> deF
What can I do this with Python?
解决方案
from string import maketrans
"Abc".translate(maketrans("abcABC", "defDEF"))
这篇关于Python中区分大小写的字符串替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文