【Python】字母表的循环迭代
字母循环迭代器
def forward(letter, jump): """字母表上的循环迭代器""" if letter.islower(): start_character = ord('a') else: start_character = ord('A') start = ord(letter) - start_character offset = ((start + jump) % 26) + start_character result = chr(offset) return result
执行1:
print(forward("a", 2)) print(forward("A", 5)) print(forward("E", 2))
执行结果
执行2:
for i in range(8): print(forward("a", i))
执行结果
数字迭代
print("-"*10 + " 分割线 " + "-"*10) for i in range(2): print(i)
执行结果
-------------------------------------------------------------------------------------
如果万事开头难 那请结局一定圆满 @ Phoenixy
-------------------------------------------------------------------------------------