How come string.maketrans does not work in Python 3.1?

前端 未结 10 2315
生来不讨喜
生来不讨喜 2020-12-18 19:49

I\'m a Python newbie.

How come this doesn\'t work in Python 3.1?

from string import maketrans   # Required to call maketrans function.

intab = \"aei         


        
10条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-18 20:10

    Hey here is the simple one liner which worked perfectly for me

    import string
    a = "Learning Tranlate() Methods"
    print (a.translate(bytes.maketrans(b"aeiou", b"12345")))*
    
    OUTPUT :::: L21rn3ng Tr1nl1t2() M2th4ds

提交回复
热议问题