Python - Increment Characters in a String by 1

前端 未结 4 1192
野性不改
野性不改 2021-01-11 15:59

I\'ve searched on how to do this in python and I can\'t find an answer. If you have a string:

>>> value = \'abc\' 

How would you

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-11 16:06

    As gtllambert beat me to my original answer, I am posting an alternative solution. You can also use map and a lambda expression to achieve the same. The lambda expression uses chr and ord to increment each character by one and chr is used to convert it back to a character.

    value = 'abc'
    ''.join(map(lambda x:chr(ord(x)+1),value))
    

提交回复
热议问题