Python - Increment Characters in a String by 1

前端 未结 4 1217
野性不改
野性不改 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-11 16:18

    value = 'abc'
    newVar=(chr(ord(value[0])+1))
    newVar1=(chr(ord(value[1])+1))
    newVar2=(chr(ord(value[2])+1))
    value=newVar+newVar1+newVar2
    print(value)
    

    Here is what I came up with can't believe it actually worked thanks for the challenge using python 3

提交回复
热议问题