当我输入"abc"
我想得到"bcd"
作为输出。
所以我想要A
to be B
and B
to be C
等等直到Z
这将是A
。
那么我该怎么做呢,我一点也不知道。
您可以使用translate直接将一个字母更改为另一个字母:
try:
from string import makestrans
except ImportError:
maketrans = str.maketrans
from string import ascii_lowercase
#old = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
#new = 'bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA'
offset = 1
old_lower = ascii_lowercase
new_lower = old_lower[offset:] + old_lower[:offset]
old = old_lower + old_lower.upper()
new = new_lower + new_lower.upper()
# Create a translate table.
trans = maketrans(old, new)
# Translate your string using trans
print("abc".translate(trans))
# bcd
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)