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

前端 未结 10 2289
生来不讨喜
生来不讨喜 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:18

    maketrans is a string function

    use below logic to use translate using maketrans

    print('maketrans' , '& translate')
    intab = "aeiou"
    outtab = "12345"
    str = "Fruits are delicious and healthy!!!"
    trantab = str.maketrans(intab, outtab)
    print (str.translate(trantab))
    

提交回复
热议问题