def increment(in_str):
# loop over each letter
for idx in range(0,len(in_str)):
# convert to a number
char_val = ord(in_str[idx])
if char_val == ord("z"):
# if 'z' - replace with 'a'
in_str[idx] = chr("a")
else:
# otherwise +1 and convert back to char
in_str[idx] = chr(char_val + 1)
我想你想要
ord()
,这是chr()
的倒数;一旦你的字符是一个数字,就更容易+1(别忘了包装)然后使用方法处理每个字符串(在循环中调用此fn-每个单词一次):
相关问题 更多 >
编程相关推荐