string1='abcd-1234'
print(string1.translate(string1.maketrans('abc','ABC'))) a='aeiou'
b=''
string2='aasdfwe'
print(string2.maketrans(a,b))
print(string2.translate(string2.maketrans(a,b)))

python translate maketrans 字符串替换的更多相关文章

  1. python文件操作--字符串替换

    如把test.txt文件的 所有 AAA 字符串 替换成 aaaaa with open('test.txt','+r') as f: t = f.read() t = d.replace('AAA' ...

  2. python 字符串替换功能 string.replace()可以用正则表达式,更优雅

    说起来不怕人笑话,我今天才发现,python 中的字符串替换操作,也就是 string.replace() 是可以用正则表达式的. 之前,我的代码写法如下,粗笨: 自从发现了正则表达式也生效后,代码变 ...

  3. Python正则表达式如何进行字符串替换实例

    Python正则表达式如何进行字符串替换实例 Python正则表达式在使用中会经常应用到字符串替换的代码.有很多人都不知道如何解决这个问题,下面的代码就告诉你其实这个问题无比的简单,希望你有所收获. ...

  4. Python3字符串替换replace(),translate(),re.sub()

    Python3的字符串替换,这里总结了三个函数,replace()和translate()和re.sub() replace() replace() 方法把字符串中的 old(旧字符串) 替换成 ne ...

  5. Python 字符串_python 字符串截取_python 字符串替换_python 字符串连接

    Python 字符串_python 字符串截取_python 字符串替换_python 字符串连接 字符串是Python中最常用的数据类型.我们可以使用引号('或")来创建字符串. 创建字符 ...

  6. python文本 maketrans和translate

    python文本 maketrans和translate 场景: 过滤字符串的某些字符,我们从例子出发 >>> tb=str.maketrans ('abc','123')    & ...

  7. StackOverFlow排错翻译 - Python字符串替换: How do I replace everything between two strings without replacing the strings?

    StackOverFlow排错翻译 - Python字符串替换: How do I replace everything between two strings without replacing t ...

  8. python 字符串替换

    字符串替换可以用内置的方法和正则表达式完成.1用字符串本身的replace方法: a = 'hello word'b = a.replace('word','python')print b 2用正则表 ...

  9. python字符串替换的2种有效方法

    python 字符串替换可以用2种方法实现:1是用字符串本身的方法.2用正则来替换字符串 下面用个例子来实验下:a = 'hello word'我把a字符串里的word替换为python1用字符串本身 ...

随机推荐

  1. CUDA: 共享内存与同步

    CUDA C支持共享内存, 将CUDA C关键字__shared__添加到变量声明中,将使这个变量驻留在共享内存中.对在GPU上启动的每个线程块,CUDA C编译器都将创建该变量的一个副本.线程块中的 ...

  2. Java for LeetCode 117 Populating Next Right Pointers in Each Node II

    Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tre ...

  3. 【转】Java中的代码点与代码单元

    转载自:http://blog.csdn.net/xujinsmile/article/details/8526387 最近看core java,之前一直不明白,看了不少帖子和博客,总算搞明白了. J ...

  4. mini2440 u-boot下设置tftp

    在烧写好u-boot后,重新启动mini2440,一直按空格键进入u-boot界面: U-Boot 月 - ::) modified by tekkamanninja (tekkamanninja@. ...

  5. MVC+Ext.net零基础学习记录(一)

    由于最近开发一个项目,决定使用MVC+EXT.NET,决定将学习的这个过程记录下来 本人和很多菜鸟一样,之前既没有使用过MVC开发,也没有接触过EXT.NET,所以这将是一个大家共同学习的过程,文章中 ...

  6. 改善C#程序的建议10:用Parallel简化Task

    在命名空间System.Threading.Tasks下,有一个静态类Parallel简化了在同步状态下的Task的操作.Parallel主要提供了3个有用的方法:For.ForEach.Invoke ...

  7. wordpress汇总(持续更新)

    在wordpress上新建编辑了几个页面,总是不能正常发布预览.经调查是由于固定链接的设置有问题导致的.打开左侧栏目“设置”中的固定链接项,可以看到目前所选的是“自定义结构”型.将其更改为“朴素”型后 ...

  8. leetcode 43. Multiply Strings(高精度乘法)

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  9. 1135 Is It A Red-Black Tree(30 分)

    There is a kind of balanced binary search tree named red-black tree in the data structure. It has th ...

  10. 【Lintcode】028.Search a 2D Matrix

    题目: Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the f ...