字母循环迭代器
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)
执行结果
标签:迭代,Python,character,forward,start,字母表,letter,print From: https://www.cnblogs.com/phoenixy/p/17126439.html